flash actionscript:
When I click on a button that I have, is there an easy way to disable all buttons on a specified level? I've got a button on that loads a swf into _level25. I'd like to disable everything clickable on _level5 and _level20 Is this easily done? I tried this: _level20.enabled = false; but that method doesn't work... Any suggestions?
I take it you need to keep seeing those levels? If not: _level5.visible=false Should do it.
Otherwise, you might try using a for.. in loop: for(var mc in _level5){ if(_level5[mc].enabled){ _level5[mc].enabled = false; } } for(var mc in _level20){ if(_level20[mc].enabled){ _level20[mc].enabled = false; } } or combine the two: var levels = [_level0,_level5,_level20]; for(var lev in levels){ for(var mc in levels[lev]){ if(levels[lev][mc].enabled){ levels[lev][mc].enabled = false; } } }
I tried your code like this: var levels = [_level5,_level20]; for(var lev in levels){ for(var mc in levels[lev]){ if(levels[lev][mc].enabled){ levels[lev][mc].enabled = false; } } } And it didn't work...
No, I mean put some buttons on _level0 and see if that code works. Reason I ask is because it works for me on _level0, but I haven't tested on other levels. I think it's very unlikely it would work on _level0 and not other _levels, so by asking you to try it on _level0 I know that if it does not work for you on _level0, while it does work for me on _level0, there is some other factor.
[quoted text, click to view] > to use a _level as a parameter, use the string representation and then use the > eval() function to return a reference to the object:
Interesting, but how come it works on _level0 to create an actual reference in the array? Is it because the _levels don't exist at the creation time of the array?
I just broke down and created a couple functions on _level0 to call at anytime that disables all the buttons specifically. There are about 12 buttons that get disabled and reenabled... If ever I add a button, I'll just add the extra code. Probably not super efficient, but it works for now.
yes, your _levels must be instantiated before trying to reference them. if you define your array after all the _levels that it contains are instantiated, you'll have no problems. also josh, you don't want to execute the disabling code (using strings or direct references to existing _levels) until all the movieclips/buttons that you want to disable exist. after that there should be no problem.
I find it easiest to just cover everything with an invisible button for which the handcursor is disabled. Here's my way to disable all rollovers and clicks: 1. Create a button with a rectangel in its hit state and nothing in its other states. Let's call it clickTrapButton. 2. Place it above everything on the level you want to disable. 3. Scale the button to the same size as the stage (or the area you want to disable) 4. Disable the hand cursor like this: clickTrapButton.useHandCursor = false; 5. Initially you should set clickTrapButton._visible = false so that your buttons underneath are enabled. 6. Whenever you want to disable the specific level, just set clickTrapButton._visible = true; Of course, if you only want to disable button pressing but still want the rollovers to work, this method won't work.
Don't see what you're looking for? Try a search.
|