开发者

Accessing a variable declared in fla from document class

On the stage I have a movieclip by the name of rect_mc. Inside it have have a MovieClip square_mc开发者_Go百科.

In the time line that I get when I double click on rect_mc (timeline of rect_mc) I have written the following code

var width1:Number;
width1 = sqaure_mc.width;

How can I access width1 from the document class?

The thing that I want to is access the variable declared (width1) in the timeline of rect_mc. Just for the sake of a example only I choose the width of MovieClip.

My doubt is how can access a variable declared inside the timeline of rect_mc from the document class. It could be any variable.

My document class is:

package
{

    import flash.display.MovieClip

    public class Test extends MovieClip
    {
        public function Test()
        {
            trace(rect_mc.width1);
        }
    }
}


I absolute not recommend using variables in the timeline, it is a very bad practice. In your case you could do something like this:

  1. In the timeline of rect_mc: (call the function init in the document class and pass the width)

    MovieClip(parent).init(sqaure_mc.width);

  2. In your document class:

    package {

        import flash.display.MovieClip;
    
        public class Test extends MovieClip
        {
            public function Test()
            {
    
            }
            public function init(width1:Number):void
            {
                trace(width1);
            }
        }
    

    }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜