ActionScript 3.0 :: Stopping Movement After Hittest?
Jan 29, 2011
I am trying to create a sort of RPG. I currently have four way directional movement working, but I'm having difficulty figuring out code to make the character stop moving when he touches a wall, and them move again when you press a different key.
Normally i wouldn't find this difficult, except most of the walls are angled, not straight lines. I'm using hitTestPoint for collision detection, and that works just fine. I just don't know good code for making the character stop.
If you take a look at this site Game then you will see that when you hit the walls or boundrys you "bounce" off them. I have accomplished stopping movement when hittest occurs but how shall I get the car to "bounce" off the walls. It would be great if you could supply the full code as I am not a great coder.
This is the URL for an awesome game. I have decided I would like to extend my flash knowledge by making a game like this. Now I have the movement downpat, but using hittests, thats how to create the game so you can not walk in certain places/areas. how to use hittest and give me the code for stopping movement when you hit a wall.
Using Flash 8 - AS2. I have a movie clip that moves from side to side based on the position of the mouse. If the mouse is right of center, the movie clip moves left, the speed based on the distance of the pointer to the center. Conversely, the same for the other direction.
Here's the AS on the clip event: PHP Code: onClipEvent(load){ speed=10; }onClipEvent(enterFrame){ this._x += (_root.center-_root._xmouse)/speed; } (the speed variable is just a simple method to slow down my motion.)
Now what I need it to do and can't figure out out is this: > How to get it to have upper and lower limits of motion. > How to get it to slow down and stop at the upper and lower limits > How to get it to stop at the limit until the mouse triggers movement back in the other direction
Logically, it could be said in this manner: 1) Move the clip right or left based on mouse position. 2) If clip _x nears the maximum (or minimum), change speed as a function of the distance remaining to the extent - in order to slow down the movement. 3) When clip _x reaches the maximum (or minimum), stop motion and permit no further motion in that direction.
I'm having trouble making a scrolling "portfolio" for a website.
Basically, when the mouse is over the left arrow, it moves right & visa versa. The problem i'm having is that I can't stop it when the mouse leaves the arrow, and it just continues moving.
It's a graphic thats moving left & right with a mask over the top.
//identitiy is the image moving function left(){ movement=10;
I am proud of myself for getting this far, but I cannot figure the rest.I have a movie clip that moves from side to side based on the position of the mouse. If the mouse is right of center, the movie clip moves left, the speed based on the distance of the pointer to the center. Conversely, the same for the other direction. [code]Now what I need it to do and can't figure out out is this:
> How to get it to have upper and lower limits of motion. > How to get it to slow down and stop at the upper and lower limits > How to get it to stop at the limit until the mouse triggers movement back in the other direction
I ended up here because of the bouncing tutorial, and for awhile there I thought I was onto the solution, but I cannot get it retrofitted to work with my mouse position stuff.
Ive got a code to move a MC on the main stage together with the mouse, in the the X axis,. difficult to explain. But now the client wants that this MC movement works only when the Y position of the mouse is over the 300 px. I thought I need a hit test or something elese. Please help. Here is the whole code.
I want it to while still easing into place like the iphone does. For example my stage is 550px. The drag and throw MC is 1650. That's 550x3. If the first image is showing starting at x axis 0 and you drag to the left it will ease into place stopping and showing the second image stopping the image at x axis 0. And the same thing scrolling to the next one and scrolling back. So the code is below and I've attached the movie that I'm working on.
i got this scene, with this specific bgm , individual frame layer. and the sounds at another layer. what i want is to stop the sound without stopping the bgm . (yes, i know the above code wouldn't work as it stops all sounds)
i just would like to know how to create an "hitTest" script inside a movieclip that is actually part of that hitTest code?I mean... I have mc A, and mc B. and the current hitTest code im using (that is on the timeline) makes mc A, destroy mc B when collide with it... but there are many mc B on the stage (with the same instance name) so, when mc A collide with one mc B, it destroys ALL mc's B... but i want it to destroy only the mc B that he collides, not all the others... maybe an hitTest script inside a movieclip B would work (somethig like "if MC A hitTest ME = i die" (not all the others)).
I am making a character walk. This code will make him wobble to the right and when thats done it will trigger him to wobble to the left and then call the function again to continue the loop.I can get the loop to work fine by calling the function but how do I STOP the function? Also I want to call it later on. Is there a way to start and stop a function?
I've been playing with carousel code, and was wondering how to change it from circular animation (carousel) to left/right linear (conveyer belt) style animation, how to change the mover code and 't.angle = i * ((Math.PI*2)/numOfItems);'
I have a mc (fStrip) which looks like a piece of filmstrip with thumbnail images in it. I want this mc to move when the users mouse is positioned over it, but I only want it to move only along it's x-axis and in a direction opposite that of the mouse. And I want it to move or flow smoothly.
I've been trying to figure this out (see my lame attempt below) but without much luck.
onClipEvent (mouseMove) { buffer=20 //movement buffer mousePos=_root.fStrip._xmouse //store mouse position if (mymouse!=_root.fStrip._xmouse){ //if the mouse has moved
I wish to get the effect of ants scuttering across the screen or up a tree, I have not decided which direction yet. I started with the tutorial code for the snow effect from kirupa, and changed it around to fit the little vector ant I created. The way I have it now looks pretty good, but the movement is a little too fluid. They obviously move in sinusoidal paths bc the code tells them to. I have about 20 copies of the main obj, and they're all a little different in size and specs (speed, transparency, etc) but what I was wondering was if there is any way I can change the code to make it a little more hectic, or erratic, not so fluid. If there is no way of doing so, it looks pretty good right now. If there is, however, I think it could look awesome. here's the code I'm using for the object.
i am controlling a tractor mc with right and left keyboard keys and let the user move the tractor till it reach a certain point where it touch a mc i want to go to a certain frame and stop the keyboard event listener and also the hit test listenerso finally the tractor is moved by user till it touches the mc then we will jump to a certain framethis certain frame will not have both of the tractor and the mcPHP Code:
I have a Mogli (Junglebook-like) Character that i got to move with the arrow keys on the keyboard.
I want the character to jump (so for example , he must while moving to the right of the "gamearea" , you must be able to hit a key (say for example the "control" key ) and then the character must jump ( go up ) and as soon as the key is released he must obviously come down.
And also how do one set movement speed on any particular movement.
I have a movie clip called frog who moves along the screen, I want him to jump when he hits any other movie clips. I can make him do so with the code below, the problem is that if I write the same function for the other movie clips it doesnt work, it still works on the first one but none others. I have tried attaching an onCilpEvent on both the frog and on all the other movie cilps so no avail.
function hitBaby(){ if(_root.babyWord.hitTest(_root.frog)){ _root.frog.gotoAndPlay("frogB");}else{ _root.frog.gotoAndPlay("frogA");}
Basicly its simply a world map with a character in the middle. You move around with the arrow keyes (in reality you move the map around and the character stays in the middle) and at certain impact you walk into houses etc etc. To accomplish this i have a movie clip in the middle named "man" and a map movie clip beneath it with the following code:
[Code]...
So far so good and no problems. This is what i need help with: I can't seem to get the "main" map to stop moving at certain points when it impacts the "man". In essence there are lakes and mountains that the character cannot cross when when he hits these i want the speed X to be 0 so to say. Im uploading my example here. It's when the movieclip in the root named "man" hits the purple line in the map movieclip its speed should go 0. Ive tried around with hittests (the code is still in the code) but i can't get it to work.
I'm using Adobe Flash CS4 on Mac (windows i'm sure i can figure out how to fix it on the mac version)I'm trying to sync some animation to sound, and my sound is all in one big file. I'm wanting to go through frame by frame and tweak it (Yes, it's a frame by frame animation, no tweening here don't ask why, it's just not), anyways, I keep trying to use the "Control -> Play" button to keep playing the sound from the area I'm working on so I don't have to start at the beginning everytime. After I hear the section I want, I want to just push "stop" and everything stop, including the audio. It would stop everything before, but now it's not stopping the audio so it will just keep playing even though I had hit stop.?
I have a simple flash movie that contains multiple frames which make up the sections of a simple site. I have built the navigation so that when you click a button, the movie advances to the proper frame/section. So far so good.My problem is that when I get to the FAQ section of the site, the movie clip that makes up the faq answers plays to the second frame, not the first. The first frame of the movie clip has a stop action in the actionscript, as does the second. But no matter what I do, any time it loads, it quickly plays to Frame 2. I do have buttons that play different frames of this movie clip, but they are attached to mouse over events and nothing else.
I'm making a basic flash website, and have already created the site structure, but I'm having trouble adding FLV and SWF, as they aren't responding as I would like.
1) I have built a basic flash photo gallery, and it works great. I have exported the SWF, but when I add that to my main sites keyframe, it plays non stop, and the buttons on that embedded SWF don't work.
2) After adding a FLV video to a keyframe, it works as I would like. Except that when I click to another keyframe after starting the video, it keeps playing. How would I be able to pause/stop the video if a navigation button to other keyframes are clicked.
I have FLV files that continue playing when I leave the frame that they are on. I can stop the playing FLV by putting this code on the following frame:
if (demo.playing) { demo.stop();}
Where .demo is the name of the instance of the .flv component.
Here is the problem - I have many frames with many flvs, and when I tell flash to stop multiple FLVs, for instance:
if (demo.playing) { demo.stop();} if (demo2.playing) { demo2.stop();}
I get this error: TypeError: Error #1009: Cannot access a property or method of a null object reference
As far as I know, flash is telling me that since the instance of "demo2" has not started playing yet (ex. the user only went to the page with the "demo" flv, but not the "demo2" flv yet) that flash has no idea what demo2 is yet. I thought using a conditional statement would remedy this, but I suppose the .swf can't stop playing something it does not yet know exists.
Is there any way I can introduce all of the flv's at the beginning of the file, yet not have them play and not have flash "forget" about them so that I can stop them using the code above? Or is there a way to have the conditional statement not error in the event that the referenced instance has not yet been "introduced"?
I really wish they would have added an "exit frame" command in AS 3.0...
I can't seem to get around my video and audio files starting when I arrive at the page. I'm even using some example code with start and stop buttons. This is in CS4 Flash. I expect it's because the ActionScript is in the wrong place because when I run the movie it flashes through all of the pages on the site without stopping at the home page. Is there some generic code that will allow me to simply swap out the name of the video or audio file I want to start. If there is, do I need to locate it on its own layer at the top of the timeline?
I've encoded an flv with cuepoints. When I play the video, it freezes at the cuepoint. I'm useing as3 on windows 7. I've removed the metaData callback from the code below as the problem occurs with and without the callback.
nc = new NetConnection();nc.connect (null);ns = new NetStream(nc); vid = new Video();vid.attachNetStream(ns);ns.play('names1680.flv');
I'm building a portfolio website and I'm using URLloaders to load new content.I want the user to be able to change the content they're loading before it completes. aka, stop the current load and load something else.
Adobe Actionscript 3.0 reference says I can use the following:"Use the unload() method to remove movies or images loaded with this method, or to cancel a load operation that is in progress."
Here's what I have (my attempt to stop the loader is in bold):
button_btn.addEventListener(MouseEvent.CLICK, newPage); function newPage(e:MouseEvent):void { loaderState=true; newDescription(); if (loading){
[code]....
I'm getting the following error on loader.unload(req); : "1137: Incorrect number of arguments. Expected no more than 0."I've also tried just using loader.unload(); but it doesn't work - the url loader just continues to load and doesn't load the new content.
I am trying to get music to play continuously, it works, but everytime you click on a button, the song restarts on the new frame.The sound code is on frame 1, and is loaded from and external file.[code]...
I need to stop an flv movie when I click a button that is not on the control bar. e.g. I have three pages in flash and when I navigate from the videos page after starting the playback of the movie, the audio from the movie continues to play. I have no idea why this is.
I am having a problem manipulating a loaded swf. I would like it to load, play once and not continue until told to. have looked around the web and have gotten confused.I have been using a loader, but I have read that to controll a time line you need a movieclip(?)so I had created an empty mc, and placed the loader with the swf in the mc.
var TIMER_DELAY:Timer = new Timer(3000, 1); // 8 second delay TIMER_DELAY.addEventListener(TimerEvent.TIMER, EXMove); function EXMove(event:TimerEvent):void