Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

actionscript 3 - as3 how to change a number by a class?

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;

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...