PDA

View Full Version : Flash 8 gotoAndStop() doesn't work?


CodeSpawn
02-09-2010, 11:59 PM
Hi, I am having problems and am hoping someone here can help.

I am trying to create things on the stage. I make them like this
var array:Array = new Array();
for (i=0; i<10; i++) {
array[i] = new Object();
instanceName = "enemy"+i;
array[i].alive = false;
array[i].clip = this.createEmptyMovieClip(instanceName, this.getNextHighestDepth());
array[i].clip.attachMovie("thing", instanceName, _root.getNextHighestDepth());
array[i].tx = 0;
array[i].ty = 0;
array[i].clip._x = 0;
array[i].clip._y = 0;
}

It makes and stores 10 instances of "thing". Named thing0-thing9

"thing" has two frames. Now it plays and flickers the two. I am trying to make it gotoAndStop() at one of the two frames at various points in the game.

However nothing works.
for (i=0; i<10; i++) {
array[i].clip.gotoAndStop(1);
}

I have tried everything. This is what I have now. It doesn't work. Can someone please help me fix it?

gnomeontherun
02-10-2010, 12:13 AM
Trace out the clips to see if you have the path right. I bet its the path.

for (i=0; i<10; i++) {
trace(array[i].clip);
}

Probably something like

array[i].clip.enemy+i

?

CodeSpawn
02-10-2010, 12:26 AM
Trace out the clips to see if you have the path right. I bet its the path.

for (i=0; i<10; i++) {
trace(array[i].clip);
}

Probably something like

array[i].clip.enemy+i

?
Thanks for your quick reply gnomeontherun.

I tried array[i].clip.enemy+i.gotoAndStop(1); but they are still flashing.:(

This is what I get from tracing.
trace(array[i].clip); -> _level0.enemy9 (I get that 0-9)
trace(array[i].clip.enemy+i); -> NaN

CodeSpawn
02-13-2010, 01:44 AM
Does any one know what I'm doing wrong? Can someone please help me?

_Aerospace_Eng_
02-13-2010, 06:57 AM
Try
array[i].clip.eval(enemy+i).gotoAndStop(1)

CodeSpawn
02-13-2010, 02:36 PM
Try
array[i].clip.eval(enemy+i).gotoAndStop(1)

No it still doesn't work. They continue to blink between the two frames...

Any other ideas? Do you think something else could be the problem instead of this code?

CodeSpawn
02-15-2010, 02:32 PM
Any other ideas? Do you think something else could be the problem instead of this code?
bump!

[Paul Ferrie ]
02-16-2010, 09:38 AM
Have you tried putting a stop() action in the "things" mc.
Surely it cant be something as simple as this?

are you able to post the fla or some stripped down version that shows the issue?

CodeSpawn
02-21-2010, 01:41 AM
No stop is not an option because I want the ability to switch between the two frames at any time.

[Paul Ferrie ]
02-22-2010, 09:05 AM
If you put a stop action on a a new layer within the things mc you will still be able to switch between frame 1 and 2 of that mc.

CodeSpawn
02-22-2010, 11:15 PM
;925256']If you put a stop action on a a new layer within the things mc you will still be able to switch between frame 1 and 2 of that mc.

Well I tried to put stop on the mc and then try to change it but it doesn't work.

[Paul Ferrie ]
02-23-2010, 08:53 AM
let me know if this works for you.

It works for me.

var array:Array = new Array();
WIDTH = 550;
HEIGHT = 400;
// A Random Number Generator
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}
for (i=0; i<10; i++) {
array[i] = new Object();
instanceName = "enemy"+i;
array[i].alive = false;
array[i].clip = this.createEmptyMovieClip(instanceName, this.getNextHighestDepth());
array[i].clip.attachMovie("enemy", instanceName, _root.getNextHighestDepth());
array[i].clip._x = randRange(0, 550);
array[i].clip._y = randRange(0, 400);
//array[i].clip[instanceName].gotoAndStop(2)
}
onEnterFrame = function () {
for (i=0; i<5; i++) {
array[i].clip['enemy'+i].gotoAndStop(1);
}
};

CodeSpawn
02-25-2010, 12:31 AM
;925788']let me know if this works for you.

It works for me.

var array:Array = new Array();
WIDTH = 550;
HEIGHT = 400;
// A Random Number Generator
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}
for (i=0; i<10; i++) {
array[i] = new Object();
instanceName = "enemy"+i;
array[i].alive = false;
array[i].clip = this.createEmptyMovieClip(instanceName, this.getNextHighestDepth());
array[i].clip.attachMovie("enemy", instanceName, _root.getNextHighestDepth());
array[i].clip._x = randRange(0, 550);
array[i].clip._y = randRange(0, 400);
//array[i].clip[instanceName].gotoAndStop(2)
}
onEnterFrame = function () {
for (i=0; i<5; i++) {
array[i].clip['enemy'+i].gotoAndStop(1);
}
};

Wow I could have sworn that that was one of the ones I tried...

Oh well maybe I did something wrong when I tried it.

Any way. It works! Thank you for your help!

[Paul Ferrie ]
02-25-2010, 07:45 AM
Ah nice one:thumbsup: