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:
In the timeline of rect_mc: (call the function init in the document class and pass the width)
MovieClip(parent).init(sqaure_mc.width);
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); } }
}
精彩评论