Itamar Marom
Itamar Marom

Reputation: 525

Accessing a MovieClip on script? (AS2)

I'm used to working with AS3, but due to recent events I need to work with AS2, and I'm having trouble with a simple task:

How do I access a MovieClip in AS? I drew something, converted it to a symbol (of type MovieClip) and ticked "Export for ActionScript". I gave it the name "MyMC". now, when I'm in some other MovieClips action, how do I access the MovieClip I drew on stage before?

Upvotes: 0

Views: 2548

Answers (1)

shanethehat
shanethehat

Reputation: 15570

If it's an object on the stage you need to give it an instance name using the properties panel, and then you can access it through the _root property:

enter image description here

_root.myMc.doSomething();

Use of Identifier:

Telling a library symbol to export for actionscript works in a similar way to in AS3. The export name you assign is a name that you use to create an instance of that symbol, using the attachMovie function:

var myMC:MovieClip = this.attachMovie("instanceName","MyMC",this.getNextHighestDepth());

attachMovie accepts 3 parameters:

  1. instanceName: this is like the name property of a DisplayObject in AS3. It is a unique name that you assign to each instance of the symbol you create.
  2. Library Identifier: This is the name that you put into the Identifier field when creating the symbol.
  3. Depth: The depth of this MovieClip on the display tree. You can target a specific depth, or use getNextHighestDepth to place it in the highest available depth, same as using addChild in AS3.

Upvotes: 1

Related Questions