Controlling a movie clip within a button?

I am trying to control a movie clip which is contained in a button.
I was told this could be done in Flash MX, if it can then I am doing something wrong.

I have an instance of my button placed on my main timeline called aubutton

Withing this button there is movie clip symbol instance named centre

I am using the following script on the main timeline instance of the button to try and control the movie clip in the button:


on (rollOver) {
	tellTarget ("aubutton.centre") {
		gotoAndPlay(2);
	}
}

yet nothing happens :frowning:

What am I doing wrong?

on (rollOver) {
_root.aubutton.centre.gotoAndPlay(2);
}

I think you have added the actionscript in the wrong place, do not put it in the actual timeline of the button you have created

This should work if you go to the main timeline, click the button once, right click and go to actions and then add the script… that is if you remember to give those movies an instance name :slight_smile:

try:
tellTarget("/aubutton/centre") {
gotoAndPlay(2);
}

He’s using Flash MX, so he can better use the dot syntax instead of the slashes… they’re deprecated (Flash 5)

ya…I believe the code would be:
_root.aubutton.center.gotoAndPlay(2);
correct me if i’m wrong

you were told wrong (kindof heh)

movieclips and instances of the such cant (well they can but not through conventional means) be accessed from within buttons because the button states reset the movieclip instances eachtime a state is triggered.

You can see the effects of this by making a button (lets say myButton) and using a movieclip (say, oh I dont know, bob) for its button states. Offset it a little for the rollover state (so you know its changing) then assign the button the following code:


myButton.onRollOver = function(){
	for(obj in this) if (typeof this[obj] == "movieclip") trace(obj);
}

bob will not be shown. Instead you’ll get instance2 as a reference. Do it again and you’ll get instance4. What happens is that no name references are kept from within a button and each time a keyframe is reached, each instance in that keyframe is reinitiated with the default name assignment which is instance + movieclipcount. Each time you rollOver that button, our clip bob gets reinitiated and renamed for each state being instance1 for the normal, instance2 for the rollover, instance 3 for the rollout (back to normal state) and instance4 when rolling back over again etc.

What to do what to do?

option 1: instead of using a button, use a movieclip. MX allows all button events to be handled by movieclips and the correct referencing of contained movieclips are kept. The only thing you dont get is your button states

option 2: on that inner clip in the button, assign a variable (either global or in root or in some way easily accessible - even in the button itself using _parent) that would allow you to reference that clip through that variable and not through the button object.

for instance, in the previous example, you can put in the first frame of bob:

_root.bobInButton = this;

Then to reference bob, use

_root.bobInButton

or for the case of in the button directly

_parent.bob = this;

and

myButton.bob;

And youre set. Because bobInButton is set in _root by bob in its first frame, it is set whenever bob is initiated - which is every time a button state is handled. Since bobInButton is also set to this and not through the button object (where then the name of the bob clip would be needed - something we dont know since its always instance+some#) the correct reference to that movieclip object is used no matter what its actual name is. As a variable in that button, too, as just “bob” you are no longer referencing a moviclip directly but a variable pointing to that movieclip.


myButton.onRollOver = function(){
	this.bob.gotoAndStop(2);
}

Similarly you may have problems using textFields … to access the INSTANCE of the textfield, you would have to do the above, though you can change the text easily enough using a variable name for the text contents (Flash 5 style) as specified in the var input text of the textfield. This var then gets associated with the movieclip containing the button (NOT the button object itself), where, changing that var will change the contents of that text.

thanks for that info.

The script is in the right place, its just wrong.