as3 how to change a number by a class?

拜拜、爱过 提交于 2020-01-07 09:20:35

问题


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;


回答1:


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.



来源:https://stackoverflow.com/questions/25968898/as3-how-to-change-a-number-by-a-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!