0

I've got a FLA document for an animation I'm creating and I'm wondering how I use an external AS file when the animation has multiple scenes/timelines.

Do I just put every function I reference in the AS file and then call the functions from within the animation timeline when I need them? Is there a better way to do this?

Thanks

Phill
  • 546
  • 1
  • 5
  • 16
  • More information needed. What is your output? where does jquery-animate fit into this question? What is the nature of the functions in your as file? Most likely, you just want to re-use code on multiple timelines? That just involves having your movie clip (timeline) objects use your .as file as their base class. Then all the vars and methods of that class (.as file) will be available in those timelines. – BadFeelingAboutThis Mar 14 '16 at 23:36
  • Hello, sorry, I accidentally tagged the wrong 'animate'. Yes, I want to reuse code on multiple timelines. Is there documentation for this anyway? I tried the official docs, but I could only find references as to how to set it up, and not how to make it all work with multiple timelines, traversing across them, and that sort of thing. – Phill Mar 14 '16 at 23:43

1 Answers1

1

Yes, you can attach the same .as3 file to multiple movieClips using Export for actionScript then use

parent.yourfunctionName();

To access various functions, as long as those functions are public:

public function doSomething ():void { trace ("function was called from timeline") }

if you need to move further up, do parent.parent.parent etc, or root.instanceName.instanceName etc

Alternately (and better), you can put all your public functions in a document class using file->settings->script->document class, and then use something like parent.parent or root to reach your functions, or you can have the document class pass a reference to itself to all movie clips that require communication:

as3 calling a function in Main.as Document Class from another class

Placing scripts on the timeline is done less often since As2, but it's still the easiest way to have something happen at a certain point in the timeline, and it still works. If you want to do it a harder way you can listen for certain frames or labels from within an enterFrame handler on your movieClip code.

Community
  • 1
  • 1
Carl Lydon
  • 86
  • 5
  • using "parent.parent.parent" is what beginner do and is the best way to achieve the weakest, most unstable and most difficult code to debug. – BotMaster Mar 15 '16 at 10:12
  • Yes, that's why I said you can do something like "have the document class pass a reference to itself to all movie clips that require communication." That's a more professional way to do it, but might be overkill for a beginner or for a project that sounds like it's more about animation than programming. – Carl Lydon Mar 15 '16 at 14:30