How to make a movie clip follow the player

Ok I want to make spawn able enemies and when they get in like 5 pixles in range they start to follow the player they are moving and if they switch directions it will go to another frame that will make it look like they are running in that direction. How can this be acheived?

use Math.atan2() to find the angle between the player and enemy.

Similar Messages

  • Boundary for movie clips following the mouse

    here's my AS...
    myInterval = setInterval(KBMOglobal,15);
    function KBMOglobal () {
    KBMOglobal1._x -= (KBMOglobal1._x - _xmouse)/10;
    KBMOglobal1._y -= (KBMOglobal1._y - _ymouse)/10-2;
    ok, so my movie clip follows the mouse around, with a small
    delay and the y axis is slightly lowered. the stage of my movie is
    380 x 640. does anyone have any suggestions on how to create a
    boundary, equal to the size of my stage, that does not let the
    movie clips that follow the mouse extend past? does that even make
    any sense? essentially, i would like the movie clips to follow the
    mouse, the entire movie clip stay visible on the stage. because of
    the positioning of the items on the stage that initiate this
    function, i only have to consider the width of each movie clip,
    which luckily is a constant = 200. does that make any sense? let me
    try this all again....
    how do adjust the above function so that the movie clip,
    KBMOglobal1 (which has a width of 200) stay within the horizontal
    limits of the stage (which is 380)?
    thanks for your time and to everyone in this forum that has
    been so very helpful with all my questions in this project so far,
    yall rock!

    quote:
    Originally posted by:
    NickTheNameless
    this is almost working perfectly, however i need to adjust
    the boundary of the x axis. for some reason, the movie clip stops
    following the mouse when it reaches half way across stage,
    horizontally.
    would you please be so kind to explain what your script is
    doing? because i'm not a total idiot, i realize i could probably
    replace 380 with 760 (double the width of the stage) and it would
    work as expected. however, if you could spare the time to explain
    what the following two lines are doing, step by step....i'll give
    you my first born.....
    KBMOglobalGeneralCancelDispatch._x<0?KBMOglobalGeneralCancelDispatch._x=0:KBMOglobalGenera lCancelDispatch._x;
    KBMOglobalGeneralCancelDispatch._x>380-KBMOglobalGeneralCancelDispatch._width?KBMOglobalG eneralCancelDispatch._x=380-KBMOglobalGeneralCancelDispatch._width:KBMOglobalGeneralCancel Dispatch._x;
    thanks again for your time!
    do you know ?: operator? it is like if...else... statements,
    when we say:
    somethingIsTrue ? do1() : do2();
    it is exactly same meaning like:
    if (somethingIsTrue) {
    do1();
    } else {
    do2();
    Now, we look at this line:
    KBMOglobalGeneralCancelDispatch._x<0?
    KBMOglobalGeneralCancelDispatch._x=0:
    KBMOglobalGeneralCancelDispatch._x;
    it is same like
    if (KBMOglobalGeneralCancelDispatch._x<0) {
    KBMOglobalGeneralCancelDispatch._x=0
    } else {
    KBMOglobalGeneralCancelDispatch._x

  • How do you make a movie clip face the mouse

    How to you make a movie clip rotate so it's always facing the
    mouse?

    thanks a lot! I got the code to work, I just modified it a
    bit.

  • How to keep a Movie Clip on the screen for 5 secs.

    I am having trouble with keeping a movie clip on the screen.
    I am setting it up to play a movie using the .onPress function. It
    is calling the movie but only shows it for a split second. How can
    I make the movie stay on the stage for 5 seconds? Here is how I
    have it coded:
    rc1MC.onPress = function() {
    if (rc1MC.hitTest(_xmouse, _ymouse, false)){
    _global.correct++;
    updateStats();
    var c1:MovieClip = this.attachMovie ("correct1_mc",
    "correct1",4300);
    var ymov = this._y;
    var gravity = 20;
    c1.onEnterFrame = function() {
    ymov += gravity;
    xmov *= 0.5;
    c1._rotation += 5;
    c1._x += xSpeed;
    c1._y = ymov;
    if (c1._y>stageHeight) {
    c1.removeMovieClip();
    delete this.onPress;
    Thanks Brandon

    Got my answer...
    http://forums.verizon.com/t5/FiOS-TV-Technical-Assistance/For-Those-of-You-Who-Want-to-View-Subscrib...

  • How do I recerence Movie Clips on the Main Timeline from inside a class?

    Hey everyone, this might be a stupid question but I thought
    I'd ask cause it's making me nuts. I'm all of 2 days into AS3
    (coming from not using Flash at all in YEARS) so feel free to
    consider me ignorant. I do have plenty of application development
    experience in other areas though.
    I can't seem to create a class that can reference an instance
    of a movie clip on my main timeline. I'd post code of what I've
    tried but I've gone through so many desperate edits & wild
    guesses that it was just garbled junk before I deleted it all.
    Basically here's how I figured Flash could work, though maybe
    it doesn't work this way at all.
    I'm assuming that with AS 3 being so big on being a true
    object oriented environment, I wouldn't need to mix my code and
    interface together. Preferably I'd be using the Flash authoring
    tools just to design my interface. Create a button... place it
    somewhere... give it an instance name. Roughly the equivilant of
    Apple's InterfaceBuilder for those of you that might be familiar
    with Cocoa development. I can see maybe having to put a few lines
    of ActionScript onto frame 1 (though really I'm hoping Flash would
    have a better method of kicking off the application at this point
    that using code tied to frames) to load my classes & such, but
    after that I'd like all of my code to be held in external class
    files.
    So maybe I've got:
    Interface.fla - My interface
    Button_1
    Button_2
    TextField_1
    Main.as - My main controller class using to handle all of my
    applications behavior
    SomeClass.as - Some helper Class
    SomeOtherClass.as - Some helper Class
    Main.as would have instructions in its initialization method
    to go ahead & attach events to buttons & initialize
    anything else that needs to happen when the application starts.
    From there on it would all be objects communicating back &
    forth. Button_1 would get clicked with would fire
    Main.someMethod(). Main.someMethod() would then do it's thing and
    set the value of TextField_1. All very clean & code is very
    separated from interface.
    Unfortunately I can't for the life of me figure out how AS3
    classes reference each other like that. There doesn't seem to be
    any kind of a global 'root' or '_root' I can use to locate any
    movie clips on the stage. I've searched the help & the web for
    any kind of simple tutorial but to no avail. My job has tasked me
    with building a flash app for a project but I'd really rather not
    have a tone of ActionScript just shoved into frame 1. That just
    seems... ugh! (::shudder::)
    Can someone maybe point me in the right direction here? I'm
    really willing to do my homework but I can't seem to locate the
    info I need to get started. Also, is there an ActionScript IRC
    channel or something maybe?
    Thanks,
    Cliff

    I worked with the problem last night and the solution I
    started coming to involved creating my own custom document class
    based off which extends MovieClip. My thought is that way I have
    access to the initialization routine of the timeline itself and
    that all of the elements on the main timeline should be
    "properties" of my custom class.
    Is this correct? Is there a down side to doing this & if
    so what is it & why?
    Also, just for my reference, the last time I did anything
    with ActionScript I think I was using '_root' to target the main
    timeline. WHat are the global variable names in AS 3? Is it just
    'root' & 'stage' or 'Root' & 'Stage' or what?

  • How to make my movie clip move slowly towards right after a few seconds?

    Hi,
    I have the following code which will bring my Banner_mc onto the middle of my Introduction page with some effects. Now, I want this movie clip to wait for a while and then move to right until it disappear with the same effects. How can I do that?
    var BannerFadeTween:Tween=new Tween(Banner_mc, "alpha", Strong.easeOut, 0 , 1, 6, true);
    var BannerRotateTween:Tween=new Tween(Banner_mc, "rotation", Strong.easeOut, 360 , 0, 6, true);
    var BannerXTween:Tween=new Tween(Banner_mc, "x", Strong.easeOut, -300 , 500, 6, true);
    var BannerYTween:Tween=new Tween(Banner_mc, "y", Strong.easeOut, -125 , 300, 6, true);
    Thanks in advance for any help in this regard.

    Hi,
    Thanks for the reply. I wnat to make one thing clear that I am using my project SWF file on computer which doesn't have any internet connection. The other thing I can't find link for downloading the plug-ins.
    When I tried to download the file from the below link, I saw the following page:
    http://www.greensock.com/club/
    Please provide the download link for greensock TweenLite & TweenMax. Thanks.

  • How to make a movie clip button into a url link?

    Hello,
    I'm kinda new to using Flash and am trying to edit a template for a friend of mine, the problem is I'm trying to add a url link to the buttons. I tried adding this action to the button
    on(release){
    getURL(http://www.yoururl.com.);
    I saved as swf & got this error msg in the compiler errors: Symbol=but1,layer 4, frame=1 Mouse events are only for button instances
    In the library I checked the properties of the button and its a movies clip, I'm not sure if it will make any difference if I change to button or graphic?
    I would like to upload the fla and swf files but this forum doesn't seem to allow me to attach files to messages.
    Does anyone know how to do this? Any help is greatly appreciated.
    http://jaedenyoo.com

    Unfortunately that doesn't seem to be the problem, I checked and
    in my flash file its typed correctly.

  • How to make Firefox 4 locale follow the one set in Windows

    I want to use Firefox 4 in a multi tennant environment. On each workstation users of different origine can log on. Ideally of course I'd like to have everybody use the system using his own language. I already found out how to make Firefox available in multiple languages, but at the moment that can only be set manually. I am looking for a way to make FF's locale follow Windows' locale. Anybody that can give me some pointers?
    In case FF can't do this by automated I was hoping to find out where about:config stores it's settings (file / registry).

    To help other users find solutions, please return to this Thread and '''Sign-in''' to the forum with your Username and Password:
    click on '''"Solved It"''' next to the reply ABOVE that '''BEST''' solved your question
    '''DO NOT click "Solved It" next to this reply

  • How to make a movie clip invisible depending on a value in another layer?

    I am trying to make an "achievements" page for my game, where if the user has a high score greater than 100, then the achievement can be unlocked. I tried using a code like this, but it didn't seem to work!
    function Check();
    if(endscreen_mc.highscore_txt > 100)
    medals.roachLock.visible = false;
    else if(endscreen_mc.highscore_txt < 100)
    medals.roachLock.visible = true;
    else if(endscreen_mc.visible == 100)
    medals.roachLock.visible = true;
    The high score value is saved inside a shared object. What's wrong with my code, and what can I do to fix it?

    I tried doing this, but it's still not working.. 
    function Check():void
    if(Number(endscreen_mc.highscore_txt.text) > 100)
    medals_mc.roachLock.visible = false;
    medals_mc.medal_mc.visible = true;
    else if(Number(endscreen_mc.highscore_txt.text) <= 100)
        medals.roachLock.visible = true;
    This is what's inside my endscreen layer
    function showresults():void
              Rchannel.stop();
       // display current score
       endscreen_mc.scoreR_txt.text = String(score);
       // calculate, display and save (if necessary) a new highscore
       var so:SharedObject = SharedObject.getLocal("alltimeHighScore");
       if (!so.data.score || score > so.data.score)
           endscreen_mc.highscore_txt.text = String(score);
           so.data.score = score;
           so.flush();
                 Check();
       else
           endscreen_mc.highscore_txt.text = String(so.data.score);
       if(so.data.score==score)
                        endscreen_mc.score_txt.text = String(score);
                        endscreen_mc.highscore_txt.text = String(score);

  • How to make a movie clip scroll with mouse position

    Hello again.  I asked a question about parallax scrolling and I think it was the wrong question.  I am looking to control a website with similar controls as this example:
    http://www.sectionseven.com/index2.html
    I want to use this but also with both  x and y axis.  Any ideas as to where to find a tutorial as to where to do this?  It should be fairly simple, but I am having trouble.  Any help or code is greatly appreciated.  Thanks!

    Yeah, I figured it out.  simply change 0.04 to -0.04
    addEventListener(Event.ENTER_FRAME,scrollmc1 );
    function scrollmc1(event:Event):void
         if(mc.x < 911  && (mouseX > 369)) {
            mc.x += (mouseX - mc.x) * -0.04;
         if(mc.x > 369  && (mouseX < 911)) {
            mc.x += (mouseX - mc.x) * -0.04
    Here is the actual code I used on my site:
    stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    stage.align = StageAlign.TOP_LEFT;
    function enterFrameHandler(e:Event):void
              if((sliderWorkspace.x < 911 && (mouseX > 1100)) || (sliderWorkspace.x > 369 && (mouseX < 90))) {
                  var newLocation:Number = sliderWorkspace.x + ((mouseX - sliderWorkspace.x) * -0.04);
                        newLocation = Math.min(910, newLocation);
            newLocation = Math.max(370, newLocation);
            sliderWorkspace.x = newLocation;
    Let me know if this works for you

  • How to make a short clip out of the original one ?

    Some days ago, I asked a question on editing a clip in this forum. The responder asked me to provide a few seconds of the clip for his examination. But I got stuck. I didn't know how to make a clip of a few seconds out of the original clip and that it had the exact same format and properties as the original clip.
    Neither Premier nor After Effect have an ouput option such as "same as original source" .
    So, my question is how to make a short clip out of the original one with everything the same properties as the original one.
    Thanks in advance.

    May be I haven't made myself clear
    Sorry, but I think that I am still not following you.
    I want to export and render the short clip to a new file which I want to have everything the same as the original clip. Just like I cut off a few seconds off it and that few seconds becomes an independent file.
    OK, you have your original source file. It is complete and is also unaltered. If you want a "Copy" of it, just use Windows Explorer, or similar to make that Copy. If you want a separate file of your edited version of that source file (as it appears in the Timeline), use the WAB (Work Area Bar) to include just that edited instance of the source footage, and Export just the WAB. This will give you a separate file with the edits in it.
    I still feel that neither is what you want. If you can step me through, maybe with screen-caps, what you have and what you wish to end up with, I can see the operation more clearly.
    Good luck,
    Hunt

  • How do I inactivate all other movie clips except the running one.

    Hello guys
    I would need help to inactivate all other actions on movie clips while the active movie clip is running. So in my flash scen when the user makes a roll over on a movie clip I would like that movie clip to play all frames in that movie clip before the user can roll over on an other movie clip. So the active movie clip don't gets interupted. What actionscript 2.0 should I look for?
    Thanks!
    /Klas

    You could use a boolean variable in a conditional that wraps whetever functionality the objects have to prevent them from taking those actions.  So when you rollover an object it starts to activate its animation or whatever and sets that boolean to prevent any others from doing the same.  And when it completes its actions it rets the boolean.
    If you show your rollover code it might be easier to show an example, but it might be something like...
    var allowPlay = true;
    mc1.onRollOver = rolloverFunction;
    mc2.onRollOver = rolloverFunction;
    mc3.onRollOver = rolloverFunction;
    function rolloverFunction(){
       if(allowPlay){
           allowPlay = false;
           this.play(); // or whatever action your rollover executes
    and when that animation completes the movieclip resets the allowPlay to true.
    _root.allowPlay = true;

  • Garage Band 10.0.2 - How do I move clips in the editor?

    Pretty basic question about Garage Band 10.0.2.   I find it difficult to grab and move clips in the editor - the bottom window - as I could in previous versions. Instead, I'm having to go up to the top window to move clips closer together.  What am I doing wrong?

    Hold down the command key, while you click the region in the track editor and drag it. Don't click the ruler, click the wave shape in the audio region.

  • Can anyone tell me how to make a video clip in color transition?

    Can anyone tell me how to make a video clip in color transition like the opening of "Oh Brother where art though" ?
    You know the scene at the start where it starts off Black and White then as we move down the timeline it transitions to a rusty brown gradually.
    It's on the Apple site for FC Studio as a promo clip.

    how to do a keyframe trasition in the Color FX room
    I realize that you can "add" keyframes to the timeline in COLORFX, but I don't believe they are always observed, and then they usually disappear in retrieved projects, and aren't persistent if you leave the room. To remember where they are... you might mark in a keyframe on those frames in another room as a pathfinder. The behaviour is consistent with a creature of the six-legged variety.
    Method 1. If you are trying to taper the effect (any effect) in COLOR FX, the most linear approach is to render two versions of the clip; one "with", one "without" and do an opacity fade once you have returned them to Final Cut. This gives you the most control, flexibility, repeatability and consistency.
    Method 2. You may attempt to keyframe the bleach bypass settings within the node itself -- the preset that comes with COLOR doesn't have any controls, but the Nattress plugin does.
    Method 3. Set up a "blend" node with your bleach bypass feeding one of the inputs and leave the second input to default to the untreated video... keyframe a transition from "1.00000" to "0.00000" and that should work.
    Note: the keyframe timeline markers will disappear from the timeline if you exit the clip, but the effect is likely to persist. At least that was what was happening a couple of minutes ago... for me, the effect and blend performed the transition just like it was previewing when rendered. This strategy is subject to being created and rendered "on the spot right now", and I advise making sure you have your renderqueue settings ready to go... load the clip from the COLORFX room using the Mac command bar at the top of the screen and render it right away. Don't try to save it for later. Just Do It.
    An announcement went around about two weeks ago that Mr. Deakins' website was back up and running, so give him another try... poor guy has been swamped probably doing Dreamweaver maintenance... yeah, that must be it...
    jPo

  • Dynamically adding multiple instances of a movie clip to the stage with one button

    hello,
    I was wondering if there was a way to add several instances
    of the same movie clip to the stage dynamically utilizing one
    button.
    I can do one with the following code placed on the button...
    on (release) {
    attachMovie ("filledCircle", "filled1", 5);
    filled1._x = 370;
    filled1._y = 225;
    But I want the user to be able to hit the button again and
    get yet another instance of "filledCircle" on the stage.
    I also want the user to be able to drag these instances
    around...
    Any help would be appreciated...
    Thanks,
    Muhl

    Muhl,
    > I was wondering if there was a way to add several
    > instances of the same movie clip to the stage
    > dynamically utilizing one button.
    Sure thing.
    > I can do one with the following code placed on the
    > button...
    >
    > on (release) {
    > attachMovie ("filledCircle", "filled1", 5);
    > filled1._x = 370;
    > filled1._y = 225;
    > }
    Gotcha.
    > But I want the user to be able to hit the button again
    > and get yet another instance of "filledCircle" on the
    > stage.
    You're in luck, because this isn't very hard to do. The main
    thing to
    keep in mind is that each instance must have A) its own
    unique instance name
    and B) its own unique depth. In your example, the instance
    name is filled1
    and the depth is 5. The next clip's instance name should be
    filled2 at a
    depth of 6. Then filled3, depth 7, and so on. You can use a
    single
    variable to handle the incrementation.
    // code in a frame
    var counter:Number = 1;
    // code on your button
    on (release) {
    attachMovie ("filledCircle", "filled" + counter, counter +
    4);
    With me so far? The variable counter contains the numeric
    value 1. The
    second parameter of attachMovie() is provided with a
    concatenation of
    "filled" + 1, which makes "filled1". The third parameter is
    provided with
    the sum of counter plus 4, which makes 5. Obviously, we need
    a bit more.
    The button must, in addition, increment the value of counter.
    The ++
    operator handles this perfectly.
    on (release) {
    attachMovie ("filledCircle", "filled" + counter, counter +
    4);
    counter++;
    Now, it seems you also want to position the attached movie
    clip to (370,
    225). Are they call supposed to go to the same place? If so,
    you may use a
    second variable to hold a reference to the newly attached
    clip. Look up
    MovieClip.attachMovie(), and you'll see that the method
    returns the exact
    reference you need.
    // code in a frame
    var counter:Number = 1;
    var mc:MovieClip;
    // code on your button
    on (release) {
    mc = attachMovie ("filledCircle", "filled" + counter,
    counter + 4);
    counter++;
    mc._x = 370;
    mc._y = 225;
    Make sense?
    > I also want the user to be able to drag these instances
    > around...
    Then you need to handle a few events. You're dealing with
    movie clips
    here, so your best bet is to study up on the MovieClip class,
    which defines
    all movie clips. (Note, also, that the TextField class
    defines all input
    and dynamic text fields; the Sound class defines all sounds,
    etc. This is a
    very handy arrangement of the ActionScript 2.0 Language
    Reference.)
    // code in a frame
    var counter:Number = 1;
    var mc:MovieClip;
    // code on your button
    on (release) {
    mc = attachMovie ("filledCircle", "filled" + counter,
    counter + 4);
    counter++;
    mc._x = 370;
    mc._y = 225;
    mc.onPress = function() {
    this.startDrag();
    mc.onRelease = function() {
    this.stopDrag();
    Easy as that. You're simply assigning a function literal to
    the event
    of each new MovieClip instance as you create it. Take a look
    and you'll see
    each of these class members available to you -- that is, to
    all movie clips.
    MovieClip.onPress, MovieClip.startDrag(), MovieClip._x, etc.
    Wherever it shows the term MovieClip in the Language
    Reference, just
    replace that with the instance name of your clip -- or a
    reference to that
    clip (which even includes the global "this" property).
    David
    stiller (at) quip (dot) net
    Dev essays:
    http://www.quip.net/blog/
    "Luck is the residue of good design."

Maybe you are looking for