Flash Problem
- Started
- Last post
- 10 Responses
- CyBrainX
This is a scope issue.
I cannot figure out scripts for a button on a _root frame like this work.this.clip1_mc.button1_btn.onRoll... = function() {
//clip2_mc on the _root
}How would you target clip2_mc and actually get it to work?
Are there exceptions?
Are there known bugs in Flash involving this?
- CyBrainX0
and should I avoid this problem by always using _global variables and functions?
- uprise0
Not exactly sure what you are trying to do but _global vars might help if you can't figure out the _root, _parent stuff.
_global.myMain = this;
now myMain replaces _root.
so now call everything according to it's level.
1_btn.onRollOver = function() {
myMain.clip2.gotoAndPlay('over...
}hope that helps.
- alloyd0
If clip1_mc is on the root, then there's no need for the 'this' in front of it. Just use clip1_mc.button1_btn.onRollOver...
Then targeting clip2_mc would be _parent.clip2_mc, since you are putting the event handler right on clip1_mc..it's like calling a script from inside of clip1_mc.
When you use 'this', it's referiing to whatever timeline you are currently in.
- alloyd0
But wait...just noticed you are targeting a child clip within another child.
So it would be _parent._parent.clip2_mc
:)
- alloyd0
so all in all it would be:
clip1_mc.button1_btn.onRollOver = function() { _parent._parent.clip2_mc.doThisF...
- uprise0
But instead of using _parent._parent._parent._parent etc... If you have globals set up you can just target their names. Makes it a lot easier if you are deep or have a big site.
- alloyd0
uprise is right too.
An easy solution would be to just give _root a global variable name.
In main timeline:
_global.mainTimeline = this;Then whereever you want in your script you can target _root by using _global.mainTimeline.
I wouldn't use _root since sometimes you may move stuff around and renest things or load in levels...you wouldn't want to redo all ur code.
- fugged0
global variables are the devil.
- ryoshu0
import mx.utils.Delegate;
someFunction = function () {
clip2_mc.bbqsplosion();
}clip1_mc.button 1_btn.onRollOver = Delegate.create(this, someFunction);
- CyBrainX0
Thanks for the advice. I think _global functions and variables are the way for me for the time being. I'll look into that delegate deal also.