Variables in Movie Clip Instance

Hello,

I have a problem trying to define a variable in a movie clip instance from a button in another movie clip.

Currently, I have MyMC1, and in MyMC1 I have loaded another movie MyMC2…

There is a button in MyMC1 which I want to be able to cause MyMC2 to resume play and establish a new variable. I have the part where the playhead resumes in MyMC2, but not the part about defining a new variable. The code on the button in MyMC1 is this:

on(press){
this.MyMC2.play();
this.MyMC2.onEnterFrame = function(){
var skipcontentend:Boolean = new Boolean();
skipcontentend=true;
}
gotoAndPlay(14);
}

The playhead in MyMC2 does move forward when the button is pressed, and the playhead in MyMC1 skips to 14… however, the variable skipcontentend is not established in MyMC2.

Any help?

can u post ur fla?

[quote=setzer9999;2328047]however, the variable skipcontentend is not established in MyMC2.

Any help?[/quote]

That’s because skipcontentend doesn’t exist in MyMC2. You’re using the var statement to create a local variable residing in the timeline in which it was created…in this case, created in the timeline of MyMC1. The solution would be to target the variable using:
var this.MyMC2.skipcontentend:Boolean = new Boolean();
this.MyMC2.skipcontentend=true;

Alternatively, you can set skipcontentend to be a global variable accessible from any timeline using:
_global.skipcontented = true;
although you’ll have to rely on Flash automatically recognising the datatype.

This thread might help:

thank you very much for this… I learned about setting a global variable as well.

Since I need this to occur on a button press at a certain point and wish for the variable to be deleted at another point, I won’t use global in this case.

I didn’t know you had to place var BEFORE the dot notation this.whatever to get the desired effect. Good stuff.

There is an additional set of problems with this solution…

I have the code:

on(press){
this.MyMC.play();
}
on(press){
var this.MyMC.skipcontentend:Boolean = new Boolean();
}
on(press){
this.MyMC.skipcontentend=true;
}
on(press){
gotoAndPlay(14);
}

The reason I have so many on(press) is because if I do not and write the code like this:

on(press){
this.MyMC.play();
var this.MyMC.skipcontentend:Boolean = new Boolean();
this.myMC.skipcontentend=true;
gotoAndPlay(14);
}

The compiler tells me that the statements must appear within an on handler… but I’m confused because it is within an on handler?

Also, for the line:

var this.contentMC.skipcontent:Boolean = new Boolean();

It says that the statement is missing an identifier?

Help! I know how to do all this code on frame actions, but putting it on a button completely changes the whole dynamic.

Use this:

this.MyMC.skipcontentend = true;

Better still, put it all on the main timeline rather than attaching it directly to the button:

myButton.onPress = function() {
	this.MyMC.play();
	this.MyMC.skipcontentend = true;
	gotoAndPlay(14);
};

The use of ‘this’ assumes that MyMC is contained within myButton.