Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

call function in main timeline from class file

New Here ,
Jun 03, 2009 Jun 03, 2009

Hi all, How can a function in main timeline be called from class file?

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2009 Jun 03, 2009

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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2009 Jun 03, 2009

Sorry, when I put this code, I got error like this:

1120: Access of undefined property displayObj.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2009 Jun 04, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 04, 2009 Jun 04, 2009
LATEST
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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines