Collision test to play a movie clip - actionscript-3

I have a character that can move left and right and can jump. I have all this coded. I included two invisible buttons that I want, when the character runs into them, to play a movie clip. I tried to set up collision detector, but failed. I have been looking through tons of code, and can not find a solution that will help. What do I need to do in order for the mc to play when the character runs over the invisible button?

if (invisiblebutton.hitTestObject(character)) {
other_movieclip.play();
}
All of this should be running in your main game loop (ENTER_FRAME event handler)

Related

Looping frames, and using keyboard listener to continue to next frames

Im still rather new to flash.
Im currently working on animation that I want to use to present my work with. I want to run short clip, consisting of 180 frames, that continually loops while I talk. Then when I press left key on the keyboard, the animation must continue.
I can get to loop the clip, using gotoAndPlay, but as soon as add the addEventListener. The I tried to incorporate a Boolean value, but that fails as well. Any help/suggestion would be greatly appreciated
Should be as simple as creating a new symbol that will contain your animation of 180+ frames. Inside this symbol/movieclip you can add code on frames which you need to loop (F9). So on frame 180 you'd write gotoAndPlay(1);. And when you need to continue from the parent call clip.gotoAndPlay(181);

AS3 / Using different movieClips in one frame

For a project I have several movie clips into one frame in those movieClips you will find a button to go to the next movieClip.
All pages (movieClips) overlap each other.
The movie clips in this case are all different pages that I want to connect through a button.
When I click on the button in the movie clip I can not use gotoAndPlay because I want everything in the same frame. I think I should use removeChild for the other movie clips to remove them and only show the one i need when I press the button?
So is there an alternative for gotoAndPlay(); or should i just use removeChild(); if you click the button?
I have little experience with AS3 so I do not know exactly how I should do it.
You can either:
set the visibility with .visible = false/true;
set their alpha with .alpha = 0 - 1; (if they are interactive, they will stay interactive so careful about that)
remove them and add them (as you already proposed)
move them off screen (bad solution)
I would probably set their visibility. Or you can do it with removeChild. There is no gotoAndPlay() for this scenario.

How to repeat a movieclip again before it stops

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.

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.

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..