# Targeting a variable inside a MC?

**URL:** https://forum.kirupa.com/t/targeting-a-variable-inside-a-mc/265296
**Category:** Uncategorized
**Created:** [July 7, 2008, 3:23pm UTC](https://forum.kirupa.com/t/targeting-a-variable-inside-a-mc/265296 "2008-07-07T15:23:24Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![bovine](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@bovine](https://forum.kirupa.com/u/bovine)
#### Post date: [July 7, 2008, 3:23pm UTC](https://forum.kirupa.com/t/targeting-a-variable-inside-a-mc/265296/1 "2008-07-07T15:23:24Z")

</div>

I have a movie clip called curtain\_mc with this actionscript inside:

onClipEvent (load) {  
stop();  
f = false;  
}

onClipEvent (enterFrame) {  
if (this.f == true) {  
this.nextFrame();  
} else if (this.f != true) {  
this.prevFrame();  
}  
}

On my first frame I have this:  
play\_btn.onPress = function() {  
btnHandler();  
};

var btnCounter = 1;  
function btnHandler() {  
if (btnCounter == 1) {  
\_parent.curtain\_mc.f = true;  
btnCounter++;  
trace(btnCounter);  
} else if (btnCounter == 2) {  
\_parent.curtain\_mc.f = false;  
btnCounter = 1;  
trace(btnCounter);  
}  
}

I would like to change the variable ‘f’ from true and false by clicking a button but the actionscript on my keyframe doesn’t recognize the actionscript in my movieclip?? I know its a targeting issue, but not sure how to alter it in order for the two to talk to each other??

---

<div class="post-metadata">

### Author: ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)
#### Post date: [July 7, 2008, 3:51pm UTC](https://forum.kirupa.com/t/targeting-a-variable-inside-a-mc/265296/2 "2008-07-07T15:51:59Z")

</div>

Take code off curtain\_mc and replace your timeline code with:

```auto
curtain_mc.stop();
// stop curtain_mc
curtain_mc.forward = false;
// set the variable "forward" on curtain_mx to false

function btnHandler():Void {
// btnHandler function
curtain_mc.forward = !curtain_mc.forward;
// alternate the forward variable on curtain_mc
}

curtain_mc.onEnterFrame = function():Void {
// curtain_mc's onEnterFrame functions
this[this.forward ? "nextFrame" : "prevFrame"]()
// if forward is true, go to the next frame, otherwise go to the previous frame
}

play_btn.onPress = btnHandler;
// on press of play_button call btnHandler

```

Is that what you mean?

---

<div class="post-metadata">

### Author: ![bovine](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@bovine](https://forum.kirupa.com/u/bovine)
#### Post date: [July 7, 2008, 4:03pm UTC](https://forum.kirupa.com/t/targeting-a-variable-inside-a-mc/265296/3 "2008-07-07T16:03:07Z")

</div>

Wow! awesome! Bravo! Insert: Adjective meaning thank you and i’m impressed!

exactly what i wanted. and much less code.

so this line: thisthis.forward ? “nextFrame” : “prevFrame”

will have a movieclip go forward or backwards based on the ‘forward’ variable? Very Nice.

---

<div class="post-metadata">

### Author: ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)
#### Post date: [July 7, 2008, 4:09pm UTC](https://forum.kirupa.com/t/targeting-a-variable-inside-a-mc/265296/4 "2008-07-07T16:09:28Z")

</div>

? : is a conditional operator.

condition **?** if true do this **:** if false do this

It’s just a shorthand way of writing your if/else statements. The key to making it work is the toggling of the forward variable between false and true using **=!**

---

<div class="post-metadata">

### Author: ![bovine](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@bovine](https://forum.kirupa.com/u/bovine)
#### Post date: [July 7, 2008, 5:29pm UTC](https://forum.kirupa.com/t/targeting-a-variable-inside-a-mc/265296/5 "2008-07-07T17:29:01Z")

</div>

One more quick question: now if i export this swf, and load it into another FLA like this:  
createEmptyMovieClip(“curtain”,1);  
curtain.\_x = 262;  
curtain.\_y = 40;  
loadMovie(“curtainOpening.swf”, curtain);

and now i want to target that btnHandler function I tried this:

my1\_btn.onRelease = function (){  
myPlayer.contentPath = “ski3.flv”;  
this.curtain.curtain\_mc.btnHandler;  
}

but i got nothing? any suggestions?

thanks again for your help!!

---

<div class="post-metadata">

### Author: ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)
#### Post date: [July 7, 2008, 7:19pm UTC](https://forum.kirupa.com/t/targeting-a-variable-inside-a-mc/265296/6 "2008-07-07T19:19:33Z")

</div>

loadMovie(“curtainOpening.swf”, **DEPTH of loading in item** );

this.curtain.btnHandler

not

this.curtain.curtain.btnHandler

---

<div class="post-metadata">

### Author: ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)
#### Post date: [July 7, 2008, 7:49pm UTC](https://forum.kirupa.com/t/targeting-a-variable-inside-a-mc/265296/7 "2008-07-07T19:49:25Z")

</div>

```auto
this.createEmptyMovieClip("curtain", 1);
curtain._x = 262;
curtain._y = 40;
curtain.loadMovie("curtainOpening.swf");
onEnterFrame = function () {
	//check if variable exists
	if (curtain.buttonHandler) {
		delete this.onEnterFrame;
		curtain.buttonHandler();
	}
};

```
