How to repeat a movieclip again before it stops - actionscript-3

I know this question has been asked before but as a noob i did not understand the answer so im hoping someone can explain a little more for me.
I have an arrow animated along a path using a motion tween I want when a button is clicked for an endless stream of arrows to follow the path, this would be easy if you could put more than one object on a motion tween but you cant? Can anyone help with the code id need to make this happen.
Is there a way to repeat the movieclip again before its finished to give this effect?

Do you have any code, or example of exactly what you're trying to accomplish?
You can use multiple instances of the same movie clip... So (for the sake of explanation) you could animate your arrow once, make sure it's its own movieClip, put it on the stage, and test your movie...It will loop over and over. You can drag as many instances of this movie on to the stage and they will all play, over and over until it's told to stop.
If you need ALL of the arrows to be one movie clip, as to be one addressable object, you can simply select all of your positioned arrows, and convert those into one movieClip (right click, convert to Symbol)
Of course all of this can be controlled precisely through code, but need to know a bit more about what you're trying to do. hope this helps a little...

The function play() will loop your movie forever, unless you have a stop() function somewhere.
yourMovie.play();
If you want to "repeat" / "reset" a MovieClip at any time, use gotoAndPlay() :
yourMovie.gotoAndPlay(1);
If you want to verify if you are at the end of your clip, use the properties currentFrame and totalFrames :
if (yourMovie.currentFrame == yourMovie.totalFrames)
{
// ex. if you want to stop
yourMovie.stop();
}
Ref : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html
Hope that help. Be more specific, if it doesn't answer your question.

Related

Best Way To Implement Invincibility Frames in AS3

I'm making a little flash game and I want to implement invincibility frames, but I'm not exactly sure how to go about doing it. Essentially, when the player walks over an object, I want to remove a health (I know how to do this) and then have invincibility frames so that the player has time to move off of the object. Something along the lines of
if (player.hitTestObject(spikes)) {
//remove health
// INVINCIBILITY FRAMES
}
Any direction here would be helpful. Thanks!
You'd better give some details about your programming style, I mean is your programming style pure as3 or pure stage or using both as3 and stage.
I'm gonna answer your question assuming you're using pure as3 style.
If you want to make your hero invincible for everything instead of just that hitted spike, you should add a public method in your hero's ( or character's) class and a variable to keep track of how much time left to remove invincibility. Something like this
public function gotHit(){
invincibilityTimeLeft=500;//500 is miliseconds, which is a half second edit this as you wish.
isInvincible=true;
}
then in your game's Event.ENTER_FRAME loop, you should decrease your character's invincibilityTimeLeft according to passed time. When it reaches 0 or below again, you set isInvincible variable of your character as false. I hope you understand what I mean.
Best of lucks.
-Ozan

How do I create a simple on-mouse-click rotating object in flash

This question may get downvoted or go unanswered because it's not the greatest and incredible silly but anyway,
I'm taking an intro level Webanimation course this semester at UNI and had I know what their expectations are for our hand-in projects i would have never taken it up.
Basically the teacher taught us stuff to the extent of masking/tweening and very few mouse-event and basic function codes.
Now she is expecting us to make a god damn ENTIRE PIPE GAME. The one where there are a bunch of rotating pipes and you gotta rotate them in place before a timer runs out and then the water flows through them.
For this project I have to somehow figure out the following (even though she didn't teach any of this):
-creature a grid of rotate-able pipes (one mouse click I assume would do a 90 degree classic tween rotation of the object)
-creature some sort of logic hit-box value chain to make pipes decide when to fill with water (they fill with water (a.k.a turn blue inside as an animation) once they are connected to another water filled pipe, for example)
-creature multiple levels and a menu screen
-add a music track.
Now i know this site is for specific help only and you basically can't ask for help on an entire project, so for now if somebody could just help me out with the following:
How do I create a rotating pipe on mouseclick?
So I have my pipe movieclip created and I have my Mouse Event code ready but I don't have the faintest on how to make a tween within the pipe and connect it to the code so that it rotates on mouseclick.
So this far, let's say for one of the pipes, instance pipe_1, I want to do this:
pipe_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
trace("Mouse clicked");
}
I also have the simple tween of rotation already created within the instance of the pipe, but dunno how to connect it to code.
I'm supposed to figure out what to put inside the function but I honestly have no clue. Hours of googling have come up with nothing either except a 12 dollar purchasable source code for an even more complicated pipe game.
I hope somebody can at least help a bit, and thanks.
The way to rotate a clip is via it's rotation property. It defaults to 0.
If you were set the rotation property of your tile to 90, you'd rotate your pipe tile 90 degrees.
for example :
pipe_1.rotation += 90;
A tween is a means of changing a property of a given DisplayObject over time. So what you want to do is tween your rotation property 90 degrees over time.
Here is a tutorial on Tweening - http://www.republicofcode.com/tutorials/flash/as3tweenclass/
I think it'd be more beneficial for you to take the time to learn about it, than to have me just write a few lines of code to solve your problem.
StackOverflow is a place where you can ask a question, AFTER you have tried something and have hit an issue.
I have provided you with the basic concept of what you need to do, and if you take the time to learn about tweening, you'll be able to achieve your goal rather simply.
There are also tweening libraries such as TweenLite and TweenMax that simplify tweening. Not sure if your class will allow you to use them, but worthwhile to check out for your own benefit.
You can find TweenLite here :
http://www.greensock.com/tweenlite/
Are you talking about a frame by frame tween? or tweening with code?
for frame by frame tweening, you can try to do this:
pipe_1.addEventListener(MouseEvent.CLICK, f1_MouseClickHandler);
function f1_MouseClickHandler(e:MouseEvent) {
pipe_1.gotoAndPlay(2); //if the tween starts at frame 2
}
For code tweening, just call the tween function inside that handler function

AS3 : MovieClip script stop when done playing

I am a beginner with AS3 and I'm having a problem with MovieClip class.
I have a character that move through a simple script that handles collision, sound etc. Everything was working seemlessly so far but when I started adding animation, the character would stop at the end of the animation cycle.
Does someone comfortable with AS3 knows what's wrong here ?
Thanks in advance =)
Inside the Flash IDE, try clicking the instance of your character that's not looping the way you want it to (and this should be from outside the animation itself; from the container of your character), then look inside the Properties tab/window. Near the bottom, there will be a LOOPING header, and inside there you can modify the behaviour.
In case you have any problems with this, or otherwise want to have more control over the animation playhead, you can include script in the form of e.g. gotoAndPlay(1); which you might add at the last frame of your animation cycle to tell Flash to play from the start again. The frame number parameter doesn't have to be 1 of course. You could for example set up a series of animation sequences on a single timeline, and use gotoAndPlay() to have them loop internally, until an event occurs and you direct the playhead to another animation loop inside the same MovieClip.
Usually when play(); is called, an animation is being repeated all the time.
You should seek in your code for stop(); that essentially makes an animation stop, and remove it.

AS3 mouseClick ignore a movieclip

Is there a way in AS3 to make a the mouse ignore a certain movieclip? I need it to be on top of the other movieclips (due to transparancy effects), but have it in a way that allows clicking on the movieclips underneath it. I know about ".mouseChildren = false", but that only makes all the stuff inside that movieclip unclickable, but it still functions as a "barrier" on top of all the others buttons.
Is there a way to do this, or do I need to remove it completely ?
You need to set both .mouseChildren and .mouseEnabled to false before you can click on objects behind the MovieClip. This makes the mouse ignore the objects within the MovieClip and the MovieClip itself.
Source: http://pixelfumes.blogspot.com/2008/01/clicking-through-movieclips-to.html
EDIT: Oops, didn't see that comment by Alex, sorry.

How to click through a display object in Flash with AS3?

I am creating a photo editor app where, at some point, the photo you edit is supposed to be dropped between two layers of DisplayObjects (a background image and an image mask.)
There is a problem, though. When the image you are editing is dropped between the background and the image mask layers, it becomes unclickable, and therefore gets stuck there, with no chance of dragging it again. (The photo editor uses TransformManager library.)
I am looking for a way to allow you to select the image you are editing no matter if there is another DisplayObject on top of it. And that probably means finding some way to click through the image mask.
Is there a way to do that?
I tried setting mouseChildren = false on imageMask, but that didn't have the desired effect.
Many thanks.
I had similar problems and I managed to solve it by using both
displayobject.mouseChildren = false;
and
displayobject.mouseEnabled = false;
on the object that you want to click through.
How about this?
mask.mouseEnabled = false;
You can always attach a Mouse Click listener to the container, and then either use GetObjectsUnderPoint and check for your object or do a hit test and see if the mouse position is over your intended object.
The hit test would look something like this !this.YourPhoto.hitTestPoint(stage.mouseX, stage.mouseY, false)
b
If I understand your problem, this handy class should solve it:
http://www.mosessupposes.com/utilities/InteractivePNG.html
Take a look at what senocular does here, specifically in the handleUpdate method. Basically: getting a list of everything under the mousePoint to find your object.
I think I stumbled upon similar problem, although in as2.
In flash when you position movie clip over movie clip, and the movie clip on the top has any mouse events implemented, it captures all mouse events so they never reach occluded movie clip.
The solution is not to have any mouse events for the top movie clip and have the movie clip positioned at the bottom capture mouse event and redirect some of them to the top movie clip (you can check mouse position with hitTest to determine if they should be redirected).
i had a strange bug i used;
movieClip.mouseEnabled = false;
but wasn't working for some reason.. was driving me crazy!! as i have used it so many times before. tried lots of different things nothing worked then i deleted the MovieClip and the created a new one and worked.. so the MovieClip's contents must have been corrupt or something as it had a old dynamic Text Area box embedded within the MovieClip.
hope this helps someone out there..