Copy link to clipboard
Copied
Hi all, How can a function in main timeline be called from class file?
Copy link to clipboard
Copied
the class must have access to a displayobject. you can then use the root property of the displayobject (probably cast as a movieclip) to access the main timeline and therefore reference the function. for example, the following would call a main timeline function f():
MovieClip(displayObj.root).f()
Copy link to clipboard
Copied
Sorry, when I put this code, I got error like this:
1120: Access of undefined property displayObj.
Copy link to clipboard
Copied
the class must have access to a displayobject (for example, displayObj). you can then use the root property of the displayobject (probably cast as a movieclip) to access the main timeline and therefore reference the function.
Copy link to clipboard
Copied
Hi all, How can a function in main timeline be called from class file?
You can, but you really shouldn't.
Classes shouldn't "talk" to the outside directly.
Use Event dispatching to get things done.
"root" (i just threw up by just typing that word) should be avoided at all cost, especially in AS3.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more