-
gotoAndPlay(random frame label) -how?
I´ve been trying to have my movie to go to a random frame label (from 2 or 3 for each letter)when a specified key is pressed. This doesn´t work, what is wrong? How to make it work? help a sleepless beginner
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(65)) {
var Alabels:Array = new Array("a1", "a2", "a3");
var randomA:Number = random(Alabels.length);
gotoAndPlay(Alabels[randomA]);
}
Last edited by ActionMom; 11-09-2006 at 12:38 PM.
-
var Alabels:Array = new Array("a1", "a2", "a3");
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(65)) {
var randomA:Number = random(Alabels.length);
gotoAndPlay(Alabels[randomA]);
}
}
Key.addListener(keyListener)
-
Thanks gorlummeeguvnor, my problem is solved already. I got a little help from other forum too
I did have that key.addListener there in the end (just forgot to mention it here) , but my movie started to work when I added _root. before gotoAnd Play.
(I dot fully understand why _root. is needed because my function is on the main timeline but)
this works fine:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(65)) {
var Alabels:Array = new Array("a1", "a2", "a3");
var randomA:Number = random(Alabels.length);
_root.gotoAndPlay(Alabels[randomA]);
}
}
Key.addListener(keyListener)
-
a pleasure.
2 points of interest
1- i think that if you haven't put in _root then flash points the gotoAndPlay to the timeline that it is on - so if its on the _root timeline then it becomes _root.gotoAndPlay()
2- var Alabels:Array = new Array("a1", "a2", "a3"); -placing this inside the onKeyDown function creates the array every time the function is called - obviously this works but you are pointlesly creating code and a new array each time.
-
Thanks, right you are, it really is pointless to create those arrays again and again That _root. -thing i still don´t quite understand cause i´m pointing form the root to the root.. but this mom is just a beginner and don´t need to know everything -yet
-
gotoAndPlay references the current object that contains the call. In this case, it references the keyListener object. Adding _root tells the system to apply it to the timeline, rather than the keyListener object.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|