AS3如何由类更改号码? [英] as3 how to change a number by a class?

查看:182
本文介绍了AS3如何由类更改号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面code不工作:

 包
{
    公共类NUM
    {
        公共职能NUM()
        {

        }

        公共职能numto(NUM1:数)
        {
            NUM1 = 47;
        }
    }
}
 

当我在我的主要时间是:

 进口NUM;
变种N:数= 17;
numto(N);
跟踪(N); //必须是47而不是17
 

这使我如不同的错误消息:

  

未定义的属性numto访问;

解决方案

您应该努力学习ActionScript语言基础知识。看了一些一般图书,它会帮助你明白是怎么回事。

至于具体你的问题。有这样的事情引用类型和值类型。我不会解释它在这里,因为有大量的材料的话题,你可以只是谷歌它。 Number是值类型。这意味着,当你传递的方法参数数目到达那里,新的实例。它不持有引用到原来的数目。

The following code isn't working:

package 
{
    public class num
    {
        public function num()
        {

        }

        public function numto(num1:Number)
        {
            num1 = 47;
        }
    }
}

when I use in my main timeline:

import num;
var n:Number = 17;
numto(n);
trace(n); // must be 47 instead of 17

It gives me different error messages such as:

access of undefined property numto;

解决方案

You should try to learn basics of Actionscript language. Read some general books, it will help you to understand what is going on.

As to your question specifically. There are such things as reference types and value types. I will not explain it here because there are plenty of material on the topic, you can just google for it. Number is value type. This means that when you pass Number as method parameter it arrives there as new "instance". It does not hold the reference to the original Number.

这篇关于AS3如何由类更改号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆