PDA

View Full Version : A couple of actionscript problems


Solesurvivor
07-12-2003, 07:27 PM
okay, ran into these problems:

1) how to detect the ending of a movieclip? I tried to use variables, but the _root didn't detect when i changed the variable in the moveclip

2) i want to go back in my animation, but it's all located on the first frame, any suggestion on how to go back, or how to perform a 'restart' of the swf

3) how can you access buttons and movieclips in other movieclips?
I tried _root.test.btn_test.onPress for example, but that doesn't work, any suggestions?

thnx in advance

poe
07-12-2003, 07:55 PM
1) just put something like var movieEnd = true on the last frame of the movie and then check for it in the root by

if (this.movieName.movieEnd) doAction;

it is best in flash to keep varibles used in such a way local to the movie, because when you delete the movie or however you remove it, the variables will be deleted too, so it just aids a bit of garbage collection.
although this means you will have a process running checking the if on everyframe. you would be better off calling a function on the last frame of the movie that triggers the next event.

2)

for (var i in this)
{
if (typeof(this[i]) == "movieclip")
{
this[i].gotoAndPlay(1);
}
}


"this" refers to the timeline that the movies you want to restart are sitting on, so it could be changed to "_root.holder" or something. as long as you change all 3 instances

3) your code is fine...there must have been a problem with your paths
_root.test.btn_test.onPress = function ()
{
doAction
}

poe
07-12-2003, 08:05 PM
actually ive made the code from 2 into a prototype to make it more sensible


MovieClip.prototype.restarter = function()
{
for (var i in this)
{
if (typeof(this[i]) == "movieclip")
{
this[i].gotoAndPlay(1);
}
}
}


so all you need to do is call

this.restarter() if its on the same timeline or
path.to.moveName.restarter() if its burried in other movies.

it also means you can call it wherever and whenever you want without duplicating code :)

DangerAhead
07-17-2003, 12:20 AM
Movieclips should loop automatically.

so is this a movieclip you want to loop?

or when it gets to the end do you want it to do something?

every movie clip has a property called "_currentframe" and "_totalframes"

all you have to do is check every frame if

mc._currentframe == mc._totalframes

if the currentframe is equal to the totalframes then it's at the last frame and you can execute some code like this:

so put this on the outside of the movie clip you want to



onClipEvent (enterFrame) {
if (this._currentframe == this._totalframes) {
// the movie clip is done
// execute this code

.... code ......

}
}


check your addressing for the buttons. if you're on the main timeline you don't have to add the _root part. but you should be able to add the "onRelease" code to a button from anywhere.

CGTalk Moderation
01-15-2006, 03:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.