How to go to next scene if a number equals zero - actionscript-3

I'm creating game where when an object rolls over another object the object disappears and when it does 1 is taken from a thing on the stage that counts how many objects are left; however, I want it so that when it equals zero it goes to a new scene. This is my code so far:
var nObjects:Number = 5;
An.addEventListener( Event.ENTER_FRAME, handleCollision4)
function handleCollision4( e:Event ):void
{
if(An.hitTestObject(Octo)){
An.addEventListener(MouseEvent.MOUSE_UP, onStopDrag4);
function onStopDrag4(e:MouseEvent):void {
e.target.StopDrag;
if(An.hitTestObject(Octo)){
removeChild(MovieClip(Octo));
nObjects--;
trace(nObjects)
myText.text = String(nObjects);
}
}
//there are five of these when they are all deleted nObjects does equal zero
if (nObjects==0);
{
gotoAndStop(1, "Scene 3");
}

You need to close your handleCollision4 and its if statement. To help keep that clear (where encapsulation occurs) remember to always properly indent your code as it will make it easier for others (and you) to read it and spot syntax errors.
In onStopDrag4, you have what looks like a function call to StopDrag. Don't forget your parenthesis.
Your test for if (nObjects == 0) { is outside your onStopDrag4 listener, meaning it only runs once during the initial document read; you want it inside the listener so it gets run after each nObject decrement. Also, do not add semicolons after a condition.
Properly formatted, it should look like this:
var nObjects:Number = 5;
An.addEventListener(Event.ENTER_FRAME, handleCollision4)
function handleCollision4(e:Event):void {
if (An.hitTestObject(Octo)) {
An.addEventListener(MouseEvent.MOUSE_UP, onStopDrag4);
}
}
function onStopDrag4(e:MouseEvent):void {
e.target.StopDrag();
if (An.hitTestObject(Octo)) {
removeChild(MovieClip(Octo));
nObjects--;
trace(nObjects)
myText.text = String(nObjects);
}
//there are five of these when they are all deleted nObjects does equal zero
if (nObjects == 0) {
gotoAndStop(1, "Scene 3");
}
}

Related

AS3 shuffling movieclips

I've added the basic targets and applying drag and drop for my puzzle pieces, now Im having trouble making the shuffling aspect. As in, after the player completes or opens up the fla, each time will start the puzzle pieces in random places of the stage. I understand using arrays for shuffling somehow but Im not sure exactly how to achieve this. I've stored the instance of my 19 puzzle pieces inside the array but now I have no idea what to do with this array. Other tutorials were abit out of my league and leaves my head scratching.
Just started doing coding for flash professional so yeah, any help with the shuffling movie clips ie the puzzles pieces would be greatly appreciated.
Heres's my code, Im not posting the whole thing since from P1 to P19 is basically copy pasting:
import flash.events.Event;
stage.addEventListener(Event.ENTER_FRAME, EntFrame)
function EntFrame(e: Event) : void
{
P1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
function fl_ClickToDrag(event:MouseEvent):void
{
P1.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
P1.stopDrag();
}
if (T1.hitTestObject(P1.Tar1))
{
P1.x = 313.15;
P1.y = 242.75;
}
P19.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_19);
function fl_ClickToDrag_19(event:MouseEvent):void
{
P19.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_19);
function fl_ReleaseToDrop_19(event:MouseEvent):void
{
P19.stopDrag();
}
if (T19.hitTestObject(P19.Tar19))
{
P19.x = 624.35;
P19.y = 455.60;
}
}
Here is what I hope is more holistic answer.
First, ditch those inline functions. Right now you make an ENTER_FRAME listener and inside that function you have inline function defined. This means every frame tick (which is tied to your frame rate, not the main timeline), those functions are going to get created again, and since you are adding them as handlers for listeners, they will stay in memory forever.
Here is a way you code this, showing ways to reduce redundancy and get rid of those memory leaks. This assumes the following:
You have 19 objects on the stage called T1 - T19, that represent the possible locations the pieces can go.
You have 19 pieces on the stage called P1 - P19, that, and the numbers correlate to the T locations as per the correct location of the piece.
//let's create a function to randomize the piece location
function seedPieces() {
//create an array consisting of the integers 1 - 19
var unusedSpaces:Vector.<int> = new Vector.<int>;
var i:int;
for (i = 1; i <= 19; i++) {
//populate that array
unusedSpaces.push(i);
}
var curLocation:DisplayObject; //helper var for the loop below
var curPiece:Sprite; //helper var for the loop below
//loop 19 times (from 1 - 19) - one iteration for each piece
for (i = 1; i <= 19; i++) {
curPiece = this["P" + i] as Sprite; //you can get the piece this way, or use an array if you've made one, like `pieces[i];`
trace(curPiece.name);
//splice removes and returns the item at the specified index (in this case a random number between 0 and arrays length less 1) - the second parameter is amount of items to remove (just 1 for this case)
curLocation = this["T" + unusedSpaces.splice(int(Math.random() * unusedSpaces.length), 1)] as DisplayObject;
trace(" ",curLocation.name);
//move the piece to the random location:
curPiece.x = curLocation.x;
curPiece.y = curLocation.y;
}
}
//NOW, as an aside, you should use a loop to add all your listeners for the sake of sanity - if you have them in an array, loop through that, or use the sloppy way like this:
for (var i:int = 1; i <= 19; i++) {
Sprite(this["P" + i]).addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
}
//create a var to hold any piece that is currently being dragged, so you know which piece to stop drag on later
var currentDraggingItem:Sprite;
seedPieces();
function fl_ClickToDrag(event:MouseEvent):void
{
//assign this clicked item to the currentDraggingItem var
currentDraggingItem = event.currentTarget as Sprite;
//bring this one to the front
currentDraggingItem.parent.addChild(currentDraggingItem);
//you can use this one click handler for all pieces
//the piece that was actually clicked, is referenced by event.currentTarget
currentDraggingItem.startDrag();
//add the mouse up listener now that the mouse is currently DOWN
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
//listen every frame while dragging
stage.addEventListener(Event.ENTER_FRAME, EntFrame);
}
function fl_ReleaseToDrop(event:MouseEvent):void
{
//if currentDraggingItem has a value, stop drag it
if (currentDraggingItem) {
currentDraggingItem.stopDrag();
//send to the back
currentDraggingItem.parent.addChildAt(currentDraggingItem,0);
}
//remove the mouse up and enter frame listener now that the mouse is UP
stage.removeEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
stage.removeEventListener(Event.ENTER_FRAME, EntFrame);
if(checkComplete()){
//game over, do something
}
}
function EntFrame(e: Event) : void
{
//this will snap the peice to the correct spot when the mouse is touching the correct spot
if(currentDraggingItem){
if (this[currentDraggingItem.name.replace("P","T")].hitTestPoint(mouseX,mouseY))
{
currentDraggingItem.x = this[currentDraggingItem.name.replace("P","T")].x;
currentDraggingItem.y = this[currentDraggingItem.name.replace("P","T")].y;
}
}
}
function checkComplete():Boolean {
//use a loop to go through all your pieces and check if they are in the right spot. Again, you could have them in an array, or do it the lazy way
for (var i:int = 1; i <= 19; i++) {
if (!this["T"+i].hitTestObject(this["P"+i]))
{
return false;
}
}
return true;
}
Well, in general you can shuffle with the following code:
var shuffledVector:Vector.<someClass> = new Vector.<someClass>;
while (originalVector.length > 0) {
shuffledVector.push(originalVector.splice(Math.random() * originalVector.length, 1)[0]);
}
Longer, explained version:
var shuffledVector:Vector.<someClass> = new Vector.<someClass>; //We will store our shuffled vector in here
var randomIndex:int; //Random index from the originalVector
var resultVector:Vector.<someClass>; //result from the originalVector.splice(...) function
var randomElement:someClass; //Random element from the originalVector
while (originalVector.length > 0) { //We will reduce the size of the originalVector until the originalVector is empty.
randomIndex = Math.random() * originalVector.length; //Calculate a random index within the range of the originalVector from 0 to originalVector.lenght-1 (note that the range decreases by one on every loop)
randomVector = originalVector.splice(randomIndex, 1); //Use splice to remove one element at the randomly choosen index, we will receive a vector with the removed element...
randomElement = randomVector[0]; //...so we need to access the element
shuffledVector.push(randomElement); //Add the randomly choosen element to our shuffled vector
}
I've written the code for a vector as i suggest to use a vector instead of an array, but the principle behind it is the same for an array.
In your case the originalVector is a vector filled with your P1-P19 Movieclips and someClass would be MovieClip. The originalVector is empty at the end and could be replaced with the shuffled one and of course it would make a lot more sense if you put the code in a seperate function like this:
function Shuffle(originalVector:Vector.<someClass>) : void {
var shuffledVector:Vector.<someClass> = new Vector.<someClass>;
while (originalVector.length > 0) {
shuffledVector.push(originalVector.splice(Math.random() * originalVector.length, 1)[0]);
}
originalVector = shuffledVector;
}
Offtopic, but important for further coding: Someone else already mentioned, that it is not good to add EventListeners on every frame, because it is absolutely unnecessary. You only need to add the Listeners once. Your code is very repetitive, you should use a function which accepts a MovieClip, x and y then call that function 19 times.
e.g.:
function setUpMovieClip(MC:MovieClip, x:int, y:int) : {
MC.addEventListener(MouseEvent.MOUSE_DOWN, clickToDrag);
//more code...
}
within the clickToDrag function you can access the MovieClip which was clicked via the event.target property:
function clickToDrag(e:MouseEvent) : {
e.target.startDrag();
//more code...
}
I hope you get the idea.

Actionscript 3 drag and drop on multiple specific targes and change alpa for the dropped objects as well as stack targets

I have been trying to achieve three things in the project without success. I am new at this and have relied on tutorials to get this far. Here we go!!
a. I want to be able to drop label_3 and label_4 on either or targetlabel_3 and targetlabel_4 but not effect the other labels and targets.
b. I want to be able to drop label_2 on top of label_1 once it has been dropped. I am finding that when label_1 has been dropped, it hides the targetlabel_2 and label_2 can't find it's target.
c. I want to change the Alpa of each of labels _1, _2, _3, _4 and _5 to zero when they are dropped on their targets and change the Apha for labels _11, _21, _31, _41 and _51 to 100. (I have changed the Apha to 25 on these for the sake of making it easier for someone to see what I am trying to do).
I have been mucking around for days on this and have hit a brick wall.
Can anyone help please?
import flash.display.DisplayObject;
import flash.geom.Rectangle;
/* Drag and Drop
Makes the specified symbol instance moveable with drag and drop.
*/
var startX:Number;
var startY:Number;
var counter = 0;
var attempts = 0;
var rect:Rectangle;
rect=new Rectangle(100,100,700,500);
correct_txt.text=counter;
attempts_txt.text=attempts;
label_1.addEventListener(MouseEvent.MOUSE_DOWN,Drag);
label_1.addEventListener(MouseEvent.MOUSE_UP,Drop);
label_2.addEventListener(MouseEvent.MOUSE_DOWN,Drag);
label_2.addEventListener(MouseEvent.MOUSE_UP,Drop);
label_3.addEventListener(MouseEvent.MOUSE_DOWN,Drag);
label_3.addEventListener(MouseEvent.MOUSE_UP,Drop);
label_4.addEventListener(MouseEvent.MOUSE_DOWN,Drag);
label_4.addEventListener(MouseEvent.MOUSE_UP,Drop);
label_5.addEventListener(MouseEvent.MOUSE_DOWN,Drag);
label_5.addEventListener(MouseEvent.MOUSE_UP,Drop);
label_1.buttonMode = true;
label_2.buttonMode = true;
label_3.buttonMode = true;
label_4.buttonMode = true;
label_5.buttonMode = true;
function Drag(event:MouseEvent):void
{
event.target.startDrag(true,rect);
feedback_txt.text="";
event.target.parent.addChild(event.target);
startX=event.target.x;
startY=event.target.y;
}
function Drop(event:MouseEvent):void
{
event.target.stopDrag();
var myTargetName:String="target" + event.target.name;
var myTarget:DisplayObject=getChildByName(myTargetName);
if (event.target.dropTarget!=null&&event.target.dropTarget.parent==myTarget){
feedback_txt.text="Well done! You have selcted the correct label and placed it in the recommended position on the package.";
feedback_txt.textColor = 0xCC0000
event.target.removeEventListener(MouseEvent.MOUSE_UP,Drop);
event.target.removeEventListener(MouseEvent.MOUSE_DOWN,Drag);
event.target.buttonMode = false;
event.target.x=myTarget.x;
event.target.y=myTarget.y;
counter++;
correct_txt.text=counter;
correct_txt.textColor = 0x0000ff
attempts++;
attempts_txt.text=attempts;
attempts_txt.textColor = 0x0000ff
}else{
feedback_txt.text="Your attempt is not quite correct. You have either selected the incorrect label or placed it in the wrong position. Please try again.";
event.target.x = startX;
event.target.y = startY;
attempts++;
attempts_txt.text = attempts;
}
if (counter==5){
feedback_txt.text="Well done! You have correctly placed all 5 labels";
percentage_txt.text ="Based on your attempts, you have scored "+Math.round ((counter/attempts) *100)+" %";
percentage_txt.textColor = 0x0000ff
}
}
The easiest way to detect when a label is on another label is by using hittest in an enter frame event listener.
stage.addEventListener(Event.ENTER_FRAME, hit_test);
function hit_test(e:Event):void{
if (label_1.hitTestObject(targetLabel_1)) {
trace("Label_1 is hitting targetlabel_1");
label_hit();
}
if (label_2.hitTestObject(targetLabel_2)) {
trace("Label_2 is hitting targetlabel_2");
label_hit();
}
}
When the hittest is activated, the trace text is shown and the function is called. To change the alphas of the labels, use the function being called by the hittest. For example:
function label_hit()
{
label_1.alpha = 0;
label_2.alpha = 0;
label_3.alpha = 0;
}
If you are trying to have conditions to when things can be dragged, seen, or hit tested, that function is also where you can take care of them. For example, If you don't want a label to be visible until the hittest, you have the alpha set to 0 until the function sets it to 100. If you don't want a label to be drageable until then, you create the listener inside the function instead of earlier.
function label_hit()
{
label_1.alpha = 100;
label_1.addEventListener(MouseEvent.MOUSE_DOWN,Drag);
label_1.addEventListener(MouseEvent.MOUSE_UP,Drop);
}
If you want hittests to occur only after other hittests have already occured, place them in conditions and have the conditions met in the functions.
stage.addEventListener(Event.ENTER_FRAME, hit_test);
function hit_test(e:Event):void{
if (label_1.hitTestObject(targetLabel_1)) {
trace("Label_1 is hitting targetlabel_1");
label_hit();
}
if(condition)
{
if (label_2.hitTestObject(targetLabel_2)) {
trace("Label_2 is hitting targetlabel_2");
label_hit();
}
}
function label_hit()
{
var condition = true;
}

Repeat a Function when it meets the condition

I have a question about action script 3.
I am making a game, the basic rule of the game is:
an object falls from the top
the hero(user) has to avoid the object
if the object hits the ground or the hero: the hero dies or the object falls again from the top.
I am using the add child method for the object, and timer function for the fall.
the problem is:
when the object hits the ground, the function does not loop. it ends just like that. so there wont be any falling objects anymore.
please help me. thanks :)
stage.addEventListener(Event.ENTER_FRAME, addfire1);
function addfire1(e:Event):void
{
if (api1==false)//if object is not on the stage
{
randomx = randomRange();//generate random X
addChild(api);
api.x = randomx;//set x
api1 = true;//object is now on stage
}
if (api.hitTestObject(hero) || api.hitTestObject(ground))
{
falltimer.stop();
//stop timer;
falltimer.reset();
//reset fall Count to zero ;
removeChild(api);//object removed
api1=false;
}
}
function firefall(Event:TimerEvent):void
{
if (api1)
{
api.y += 20;//set speed y
}
}
Just separate the two cases: hero and floor.
if (api.hitTestObject(hero))
{
falltimer.stop();
//stop timer;
falltimer.reset();
//reset fall Count to zero ;
removeChild(api);//object removed
api1=false;
}
else if (api.hitTestObject(ground))
{
//reset object's position
api.y = -20;
}
Assuming there is only one object falling at the time I'd not remove the object but instead just move it to the original y position and a new x position. And instead of having the timer i'd create an update-function that runs every time you enter a frame.
stage.addEventListener(Event.ENTER_FRAME, update);
private function update(e:Event):void
{
if(!api1) //if object is not on the stage (same as api1==false)
{
addfire1();
}
if(api1) //if object if on stage (same as api1==true)
{
firefall();
}
}
private function addfire1(e:Event):void
{
randomx = randomRange();//generate random X
addChild(api);
api.x = randomx;//set x
api1 = true;//object is now on stage
if (api.hitTestObject(hero))
{
hitHero(); //execute what should happen to the hero when the he is hit
resetFire();
}
else if(api.hitTestObject(ground))
{
resetFire();
}
}
private function firefall(Event:TimerEvent):void
{
api.y += 20;//set speed y
}
private function resetFire():void
{
api.x = randomRange();
api.y = 0;
}
If you write it like this you don't have to mix stuff up. Try to keep everything seperated, one function does one thing. If you are making a big game try to seperate everything in classes.
Hopefully this fixes the problem and makes it easier for you to finish the game :)

How to make 3 buttons be clicked in a certain order go to certain frame? Flash AS3

I am struggling making 3 buttons be able to go to a frame when the buttons are clicked in a certain order. For example the buttons are labeled
button 1
button 2
button 3
and the order that they are needed to be clicked in is button 3, button 1, button 2 for them to go to the next frame, How can I achieve this?
This is what I have so far.
var clicked = MouseEvent.CLICK
var buttons = new Array(YellowButton, BlueButton, RedButton);
for (var a=0; a<buttons.lenght; a++)
{
buttons[a].buttonMode=true
buttons[a].addEventListener(clicked,RedYellowBlue);
}
function RedYellowBlue(event:MouseEvent):void { gotoAndStop(20); }
Thanks for your help in advance
What I recommend is to create a string object that will be assembled by clicking the buttons, and then compared to a particular sequence that you set. The beauty of this is that you can make it work for sequences of any length.
The biggest thing here is, you don't want the same event listener on all three buttons. You want their actions to be unique, otherwise, clicking one is the same as clicking all the others (which is your current code's problem.)
var checkString:String = "";
//Create event listeners and their functions.
YellowButton.addEventListener(Mouse.CLICK, yellowClick);
RedButton.addEventListener(Mouse.CLICK, redClick);
BlueButton.addEventListener(Mouse.CLICK, blueClick);
function yellowClick(evt:Event):void
{
//In each event listener function, add a letter or
//string to the checkString variable.
checkString += "y";
//Then, see if the string matches or not.
check();
}
function redClick(evt:Event):void
{
checkString += "r";
check();
}
function blueClick(evt:Event):void
{
checkString += "b";
check();
}
//If the proper sequence is red, yellow, blue, the string would read "ryb".
function check():void
{
if(checkString == "ryb")
{
//Clear the checkString for convenience before going on.
clearString();
//CODE TO GO TO NEW FRAME
gotoAndStop(20);
}
else
{
//Make sure the string is at least 3 characters long.
if(checkString.length >= 3)
{
clearString();
gotoAndStop(foo);
}
}
}
function clearString():void
{
//You will want to have a function for clearing the string.
//This is especially useful if you have a button for "start over."
checkString = "";
}
That should be sufficient to get you started. If you need additional help, feel free to comment on my answer.
To consolidate #JasonMc92's answer, you could use the name of the target as the checkString letter so you only need to call one function for all buttons.
yellowButton.addEventListener(MouseEvent.CLICK, redYellowBlue);
redButton.addEventListener(MouseEvent.CLICK, redYellowBlue);
blueButton.addEventListener(MouseEvent.CLICK, redYellowBlue);
function redYellowBlue(e:MouseEvent){
checkString += e.currentTarget.name.substr(0,1);
check();
}
//... continue on with Jason's functions
Or, since you've set them up in an array, you could also just use the buttons' indices as your check sequence. Something like:
function redYellowBlue(e:MouseEvent){
checkString += String(buttons.indexOf(e.currentTarget));
check();
}
function check(){
if (checkString == '201') {
// ... handle correct sequence
}
}
Also, just a best practice tip:
only use a leading capital for names of classes. Instance names and function names should start with a lowercase. (leading cap won't break anything, but it's standard practice)
//Here is code
var buttons:Array = new Array(YellowButton, BlueButton, RedButton);
for(var i:int=0;i< buttons.length;i++)
{
buttons[a].buttonMode=true
buttons[a].addEventListener(MouseEvent.CLICK,buttonsClickHandler);
}
function buttonsClickHandler(event:MouseEvent):void {
var button:MovieClip = MovieClip(event.target);
switch(button.name)
{
case "YellowButton":
case "BlueButton":
gotoAndStop(2);
break;
case "RedButton":
gotoAndStop(3);
break;
}
}

How would you write a For Loop that advances the currentFrame by 1 if it is below a certain Frame

I just need the correct syntax ... I keep getting errors.
Current code looks like this:
for (var i = movieClip.currentFrame; i<15; i++){
movieClip.currentFrame+1
}
What are you trying to achieve? If you want to play from a specified frame to another frame, this is not the way to go. That said, I don't undstand the current answers that are given. MovieClip.currentFrame is a read-only property. So none of the answers would actually work, none tested their code. I downvoted the answers for that. This is why you get errors too.
myMc.currentFrame = 5;
// gives an error, since this property is read-only, you cannot set it.
To jump to a certain frame, use gotoAndStop() or gotoAndPlay(), with the framenumber or framelabel as the parameter.
If you want to play a clip called myMc from the current frame to (lets say) frame 15, try this
myMc.addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void
{
if (myMc.currentFrame < 15)
{
myMc.gotoAndStop(myMc.currentFrame + 1);
}
}
As you can see we've created an enterframe listener. If you dont understand what it does; this makes the onEnterFrame function (defined below) execute every frame. Its needed because every frame it have to decide where to go, its not possible with a loop. It should be altered over time. This example works, but only if when you should play forward, or to be more specific; when currentFrame is under 15. If your at fram 20, your stuck. Lets fix that by make it play backwards too, if needed.
myMc.addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void
{
if (myMc.currentFrame < 15)
{
myMc.gotoAndStop(myMc.currentFrame + 1);
}
else if (myMc.currentFrame > 15)
{
myMc.gotoAndStop(myMc.currentFrame - 1);
}
}
ok, now it should also play backwards. Now, it would be betterr to stop checking when we've arrived at the target frame. Therefor we should remove the eventlistener.
myMc.addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void
{
if (myMc.currentFrame < 15)
{
myMc.gotoAndStop(myMc.currentFrame + 1);
}
else if (myMc.currentFrame > 15)
{
myMc.gotoAndStop(myMc.currentFrame - 1);
}
if (myMc.currentFrame == 15)
{
myMc.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
Now this should be the answer of your question. However it would be nice to make a function where you can give a target movieclip and endFrame.
function playClipTo(clip:MovieClip, targetFrame:int):void
{
clip.targetFrame = targetFrame;
// since MovieClip is dynamic, you can add non-excisting properties.
// If your using classes, you would extend MovieClip and create a public variable for this. But for now its fine.
clip.addEventListener(Event.ENTER_FRAME, onClipEnterFrame);
}
function onClipEnterFrame(event:Event):void
{
var clip:MovieClip = MovieClip(event.target); // this referres to any clip with a listener
if (clip.targetFrame)
{
if (clip.currentFrame < clip.targetFrame)
{
clip.gotoAndStop(clip.currentFrame + 1);
}
else if (clip.currentFrame > clip.targetFrame)
{
clip.gotoAndStop(clip.currentFrame - 1);
}
if (clip.currentFrame == clip.targetFrame)
{
clip.removeEventListener(Event.ENTER_FRAME, onClipEnterFrame);
delete clip.targetFrame;
}
}
else
{
clip.removeEventListener(Event.ENTER_FRAME, onClipEnterFrame);
}
}
With this function you could do this
playClipTo(myMc, 15); // ha, familiar example!
playClipTo(myMc2, 5); // another clip, play to frame 5
I hope this helps. By the way, if you need to jump from framelabel to framelabel, or need more control on speed, easing, delays, you could take a look at a tween engine, like TweenLite, this has very advanced but easy to understand way of animating with code. Its very common in the flash world, plus it saves development time for relative simple tasks like this.
inside the loop put
if (movieClip.currentFrame < theNumberToIncreaseTo) {
movieClip.currentFrame = movieClip.currentFrame + 1;
}
Maybe
movieClip.currentFrame = movieClip.currentFrame + 1
Instead of
movieClip.currentFrame+1