HitTesting edges / moving Movie Clips stage length

This is sort of a multi-layered question- I have a movie clip that I sectioned off in quadrants:
http://img401.imageshack.us/img401/2250/tempnw.jpg
The red dot is the player, the stage is the size of one square. My goal is to, when the player moves to either of the 4 edges, the next section of the quadrant comes up (meaning if the player moves to the right edge, the section that borders the right edge will slide on screen, and the old section will slide off screen).
I was wondering if there was a way to hitTest if an object is touching any part of the edges? Is the hitTestPoint method something I should look into? What I have so far is an object off screen (black rectangle), that when the player touches the quadrants slide like I want them to (at least I'm trying to make that work).
Here is my code. I know some of it's wrong and/or I'm missing something. Any help would be appreciated.
if(leftKeyIsDown && player_mc.x > -15)     //-15 is half the size of the temporary player_mc
          player_mc.x -= speed;
          if(player_mc.x < 0)     //take in account the size of the REAL player_mc
               player_mc.gotoAndPlay(1);
               stage.removeEventListener(KeyboardEvent.KEY_DOWN, pressKey);
               stage.removeEventListener(KeyboardEvent.KEY_UP, releaseKey);
               if(player_mc.hitTestObject(edge_mc))
                    map_mc.x = map_mc.x + stage.stageWidth;
          //map_mc.addEventListener(MotionEvent.MOTION_START, moveMap);
          //checkHitLocation(edge);
/*function checkHitLocation():void
/*function moveMap(event:MotionEvent):void
     var pointLeft:Point = new Point (0, 150.45);
     if(player_mc.hitTestPoint(pointLeft.x, pointLeft.y, true))
          map_mc.x -= stage.stageWidth;
Also, I have it so all the quadrants together will be in a movie clip (map_mc), and nested in that movie clip will be the individual pieces, each quadrant with an individual instance name.

I think my inability to understand array's and how to add/remove children from them is leading me to hit a wall. Would you mind helping explain it to me?
package
     import flash.display.MovieClip;
     import flash.events.KeyboardEvent;
     import flash.events.Event;
     import flash.ui.Keyboard;
     public class Main extends MovieClip
          public var ground:MovieClip;
          public var nextGround:MovieClip;
          public var player:MovieClip;
          public var keyPressed:uint;
          public var rightKeyIsDown:Boolean;
          public var leftKeyIsDown:Boolean;
          public var speed:Number = 10;
          public var land:Array = new Array();
          public var landOrigin:Number = 650;
          public function Main()
               ground = new beginGround_mc();
               addChild(ground);
               player = new player_mc();
               addChild(player);
               player.y = 200;
               rightKeyIsDown = false;
               leftKeyIsDown = false;
               stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKey);
               stage.addEventListener(KeyboardEvent.KEY_UP, releaseKey);
               stage.addEventListener(Event.ENTER_FRAME, hitting);
          public function hitting(event:Event):void
               if(player.hitTestObject(ground.groundAdd1_mc))
                    trace("hit");
                    addNewGround();
               for(var i:uint = 0; i < land.length; i++)                    //1
                    nextGround = land[i];
                    if(player.hitTestObject(nextGround.groundAdd2_mc))
                         trace("blue");
          public function addNewGround()                                       //2
               nextGround = new ground_mc();
               addChildAt(nextGround, 0);
               nextGround.x += 700;
               land.push(nextGround);
As my code stands right now I got groundAdd2_mc to trace back the second statement. From here I need to keep adding instances of the nextGround movieclip right after one another every time the player hits groundAdd2_mc, and removing all the old ones the player can no longer see.
I guess I really don't comprehend what //1 is doing, In my mind I put an instance of the nextGround_mc class in the land array and try and call it every time the player hits the appropriate hitTest, leading me to //2 addNewGround, where the new ground piece is added 'x' distance away; I'm not really comprehending how I can add only 1 instance 'x' distance away every time the player hits the hitTest.

Similar Messages

  • HitTest for multiple Movie Clip at the same time

    I have a movie it is a triangle.I duplicate it and I want to hitTest on the first triangle movie clip and I added 3 different line movie clips on the 3 side of triangle.I tried to write a code something like that.
    if(firstTriangle_mc.hitTestObject(line1_mc,line2_mc,line_3mc){
    trace("Ok");
    but I've got error.I think it is not allowed hitTestObject for multiple Movie Clips.So is there anyone have an opinion about it?What should I do?

    Here is another test for multiple movie clips for hitTestPoint but only the first work the others don't
    uc_mc.addEventListener(Event.ENTER_FRAME,hitle);
    function hitle(e:Event) {
    if (uc_mc.hitTestPoint(cub1,cub1Y,true)&&(cub2,cub2Y,true)&&(cub3,cub3Y,true)) {
      uc_mc.alpha=0.5;
    }else{
      uc_mc.alpha=1;
    The code above doesn't work.What should I do?

  • Moving Movie Clips dynamically

    Here's the deal. I have a function that I call to move the
    movie clips based on string that holds the movie clip instance
    name. The function as I have it now can be seen below listed under
    figure A. Figure B shows my call to that function. It takes in an
    array of strings and passes the current index to the function.
    Figure C shows my output panel text after I run the function.
    For some reason, the function is only moving one of my
    movieclips, and none of the others. I can tell this by tracing the
    instance ._x value, as shown in figure D. So, I know that my calls
    to the movieclip instances are correct, but why can I only move one
    card?? I know the movie clips are instantiated, as can be seen in
    Figure E, which show my objects list that I get from my debug menu.
    Any ideas/suggestions?

    My latest crack at it... I create multiple controllers for
    each movie clip, and I test the calling of the method by inserting
    a string literal as the call, still no luck. No matter how many
    times I call move, it will only work on the last card that I call.
    Framerate does not matter.

  • Moving Movie Clips with Arrow keys

    How do i make it so when i click the left arrow key, it will
    change the movie clip to make it turn around?

    Yes, that's what the code I gave you is intended to do....
    you replace that code with whatever action you need to take to turn
    your movie around.
    I have no idea what your movieclip is doing, but I'm guessing
    by your response that if it was an arrow pointing left to right
    (just an example), you want it to be pointing right to left when
    the left arrow is pressed. If you want an immediate turn around,
    then the simplest way to do that is to have another frame
    containing the movieclip that it moves to where it faces the other
    direction--and to have it appear turned around, from the toolbar
    you select Modify -> Transform -> Flip Horizontal.
    So the movieclip would live inside another movieclip that has
    two frames with stop()'s for each frame. In the first frame you
    would have the subclip facing left to right, and in the second you
    would have it facing right to left. If we call that 2-framed
    movieclip "walker", the code I provided before would
    become...

  • Moving movie clips with ActionScript

    I am trying to move four movie clips with actionscript in a
    circler motion with two buttons, one to rotate the mc’s to
    the left and one button to rotate the mc’s to the right. Here
    is a link to what I am trying to do;
    http://www.us.playstation.com/Lair/
    and it is undrer game features.

    Yes, that's what the code I gave you is intended to do....
    you replace that code with whatever action you need to take to turn
    your movie around.
    I have no idea what your movieclip is doing, but I'm guessing
    by your response that if it was an arrow pointing left to right
    (just an example), you want it to be pointing right to left when
    the left arrow is pressed. If you want an immediate turn around,
    then the simplest way to do that is to have another frame
    containing the movieclip that it moves to where it faces the other
    direction--and to have it appear turned around, from the toolbar
    you select Modify -> Transform -> Flip Horizontal.
    So the movieclip would live inside another movieclip that has
    two frames with stop()'s for each frame. In the first frame you
    would have the subclip facing left to right, and in the second you
    would have it facing right to left. If we call that 2-framed
    movieclip "walker", the code I provided before would
    become...

  • Random location for a random movie clip

    I have various movie clips which I need to appear in one of
    four locations randomly. I need the movie clip to also be random. I
    also need more than one movie clip on stage at the same time. I
    believe the following needs to be used:
    Math.random
    duplicateMovieClip
    I also believ that the method needs to be generic. Apart from
    that I am stuck.
    Any help/ideas are appreciated.
    Hope my question makes sense?

    good point. to be honest thinking about it I dont really know
    why
    I have four movie clips, which the user controls called
    user1
    user2
    user3
    user4.
    In addition I have 6 additional movie clips which I need to
    appear and move (randomly) in one of four locations (based on a
    standard stage size):
    locations 1 (start position)
    x co-ordiantes 138.3
    y co-ordiantes 62.8
    locations 2 (start position)
    x co-ordiantes 549.3
    y co-ordiantes 53.8
    locations 3 (start position)
    x co-ordiantes 137.3
    y co-ordiantes 156.8
    locations 4 (start position)
    x co-ordiantes 543.3
    y co-ordiantes 147.8
    locations 1 (finish position)
    x co-ordiantes 291.3
    y co-ordiantes 162.8
    locations 2 (finish position)
    x co-ordiantes 397.3
    y co-ordiantes 162.8
    locations 3 (finish position)
    x co-ordiantes 280.3
    y co-ordiantes 257.8
    locations 4 (finish position)
    x co-ordiantes 400.3
    y co-ordiantes 258.9
    The maximum number of movie clips moving between the two
    positions at once should be 6. Ideally more than one from one
    location
    I would also like the speed at which they move to be
    different.
    The idea is that if a colission occurs between any one of the
    moving movie clips and the avatar(user 1-4) then points are added.
    Hope this helps.
    Thanks
    ******************

  • How to stop a movie clip moving

    I'm not newbie to flash but I am newbie to coding using
    actionscript!!!
    I am trying to create a button that moves a movie clip
    ("content1") diagonally across the screen but once the movie clip
    reaches a certain x co-ordinate I want it to stop and then when I
    click another button I would like it to return to it's starting
    position. At the moment the movie clip moves if I click one of the
    buttons but as soon as I click another one it stops which it
    shouldn't it should go back in the other direction. The other
    problem is that once I've clicked a button I cant seem to get it to
    stop moving once it reaches a certain _x position it just keeps on
    moving off the stage.
    Below is the script I have so far not including any
    conditions to check if "content1" has reached it _x position
    Could anyone help please!!!!
    //on Right movie clip containing the button
    onClipEvent (enterFrame) {
    _root.content1._x += speedX;
    _root.content1._y -= speedY;
    //on Right button inside movie clip
    on (press) {
    speedX = 5.5;
    speedY = 1.33;
    //on Left movie clip containing the button
    onClipEvent (enterFrame) {
    _root.content1._x += speedX;
    _root.content1._y -= speedY;
    //on Left button inside movie clip
    on (press) {
    speedX = 5.5;
    speedY = 1.33;

    Many thanks ClBeech!!!
    I've tried the code you suggested but it doesn't seem to work
    :0(
    I'm working on a Mac using Flash Pro 8 which only has the
    option to publish as 'actionscript 1.0 or 2.0' is the script you
    supplied an actionscript 3.0?
    Below is the script with the amendments, I've changed my
    button instance names to match the script you supplied (left_btn /
    right_btn)
    stop();
    import mx.transitions.Tween;
    import mx.transitions.easing.Strong;
    var rposX = 369;
    //the ending x of the right position
    var rposY = 84;
    //the ending y of the right position
    var lposX = 116;
    //the ending x of the left position
    var lposY = 154;
    //the ending y of the left position
    right_btn.onPress = function() {
    new Tween(content1, '_x', Strong.easeOut, content1._x,
    rposX, time, false);
    new Tween(content1, '_y', Strong.easeOut, content1._y,
    rposY, time, false);
    left_btn.onPress = function() {
    new Tween(content1, '_x', Strong.easeOut, content1._x,
    lposX, time, false);
    new Tween(content1, '_y', Strong.easeOut, content1._y,
    lposY, time, false);

  • Moving a movie clip via key press event question.

    I have a project where I'm trying to move the movie clip: "wally", up and down three levels of a stage.
    However, from the default position I have him move up 145 pixels, and down 120 pixels.
    I want to limit this action to one use, meaning if wally goes up once from his default position he must come back down, and vice versa, if he goes down he must come back up(or stay on that level). Also, if he goes up the 145 pixels, he needs to come back down 145 pixels, likewise if he goes down 120 pixels, he needs to come back up 120 pixels. I might be over-thinking this, as I had to strip it back to the starting code the other day, and am at a loss once more. If this'd be easier performed by moving with keyboard arrows and case statments, let me know, as I'm stumped.
    Starting code:
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressHandler1);
    function keyPressHandler1(event:KeyboardEvent):void
              if(event.keyCode==38)
                        wally.y -= 145;
                        else if(event.keyCode==40)
                        wally.y += 120;

    use:
    wally.startY = wally.y;
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressHandler1);
    function keyPressHandler1(event:KeyboardEvent):void
              if(event.keyCode==38)
    if(wally.y==wally.startY){
                        wally.y -= 145;
    } else if(wally.y>wally.startY){
    wally.y=wally.startY
                        else if(event.keyCode==40)
    if(wally.y==wally.startY){
                        wally.y += 120;
    } else if(wally.y<wally.startY){
    wally.y=wally.startY;
    p.s. please mark helpful/correct responses.

  • Reaching a movie on the stage from inside another movie clip

    I'm trying to reach a body of text which i turned into a movie clip which is on the main stage, and have it scroll up/down whenever it rolls over the designated hot spots. Here's what i have.
    stage.addEventListener(MouseEvent.MOUSE_MOVE,down1,false,0,true);
    function down1(e:MouseEvent):void {
         if (mouseX>=0 && mouseX<=42 && mouseY>111.1 && mouseY<146.1) {
              stage.addEventListener(Event.ENTER_FRAME,scrolldown1);
         } else {
              stage.removeEventListener(Event.ENTER_FRAME, scrolldown1);
    function scrolldown1(e:Event):void {
         if(MovieClip(this.root).resume_txt.y > 219) {
              MovieClip(this.root).resume_txt.y += 5;
         } else {
              this.removeEventListener(Event.ENTER_FRAME, scrolldown1);

    Can you explain the purpose bhind these lines...
         if(MovieClip(this.root).resume_txt.y > 219) {
              MovieClip(this.root).resume_txt.y += 5;
    It seems as though if it is >219, it will move until the mouse moves out of the region.  Is there any specific aspect of it that you can pinpoint as not woking?.

  • How can I display a Movie clip from library on stage in AS3?

    Hi,
    I have a movie clip in my library and I would like to display it on the stage using AS3.
    do I have to define it as a variable?Do  I need to use this code:  addchild(movieclip);
    can I use the 'x' and 'y' to position it?
    What would the code look like?
    Ben.

    Great! it works  well ! thanks
    But I have another question, if I wanted to used the same movie clip but postion it at different x and y positions when a different btn is selected how could I do that?
    Would I have to make a copy of the movie clip and give it a different name?
    or is there an better way around it?
    Ben.

  • How do I assign a mouseclick event Listener to a simplebutton already nested in a movie clip when it's dropped on stage?

    I'm trying to assign a mouseclick event listener to a simplebutton nested within a movie clip's later frames, starting at frame 2 and up. This card, however, is not added to my game until later, and when the player clicks on it/turns it over.
    There are four files involved in this program:
    #1 The main actionscript file, which corresponds to
    #2 my dreamQuester .fla file.
    #3 my artifactCard file movieClip's corresponding .as file,
    #4 my combo1.as file corresponding to a an instance of a simpleButton named combo1 that is already
    nested --and this instance is already named-- inside/as a child of said artifactCard movieclip.
    What I've done so far isn't working:
    In my main dreamQuester.as file, when a player clicks on an artifactCard, its MOUSE_DOWN event
    listener takes them to this function (clickArtCard), where the trouble is at:
    // player clicked on the artC card--which is a child of posArt1 on stage--to turn card over:
            function clickArtCard(a_event:MouseEvent) {
                var thisArtCard:artifactCard = (a_event.target as artifactCard);
                thisArtCard.gotoAndStop(unclickedArt1);  // go to frame number of artifact
                                    // card where combo1 button is.
                thisArtCard.removeEventListener(MouseEvent.CLICK,clickArtCard);
                thisArtCard.buttonMode = false;
                trace("combo1.combo is:" + combo1.combo);
                trace("posArt1.artC.combo1 is:" + posArt1.artC.combo1);
                posArt1.artC.combo1.addEventListener(MouseEvent.MOUSE_DOWN, comboClickedWHO);
    when the artC card--the static public instance of artifactCard--is clicked, it only gets to the
    trace("posArt1.artC.combo1 is:" + posArt1.artC.combo1); which returns this error message:  
    TypeError: Error #1010: A term is undefined and has no properties.
        at MethodInfo-61()
    So do how would I declare a static public variable of this simpleButton at the start of my main .as
    file to make it defined to get a mouseDown actionListener into my pre-existing-and-named-instance
    combo1 simpleButton?
    perhaps there is a way, while the debug movie program is running, to click on the simpleButton and see exactly
    what it's parent heirarchy is, to see the name of all parents above the simpleButton incase they are
    different then what I think?
    (just in case, I was hoping to squeeze a zip file containing these files to be less than 9MB incase someone was willing to look at my files to see what I've done so far, but 9 megs is just too big! even though all graphics I've imported where turned into vector graphics with trace bitmap. I wish there was a way to check the file size of each symbol in Flash CS4, here...)
    Thank you so much for any help!
    ~Ethan

    Just use a
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
    function keyPressed(event:KeyboardEvent):void {
         //trace(event.keyCode);
         if(event.keyCode == ???){
              // play the sound
    Where I show the "???" you would replace with the keyCode for the key you want pressed for that sound.  To determine the keyCode you can use the trace line that I have commented out.
    Note that when testing in Flash you often need to disable the keyboard shortcuts in the Flash Player in order to be able to use alot of the keys.  You will find this option in the Control menu options in the player.

  • Not all my movie clips are showing up on the stage or playing

    II have 8 movie clips in 8 separate layers on my stage; they
    are set to play one after the other. First problem - even though i
    can see them all on the stage in my Flash document, when i test the
    movie, only the first 5 clips are visible, and these are the only
    ones that play through.
    why aren't the other 3 even showing up??
    i can upload the file if necessary...

    i have been looking at yer FLA for 5 min and i have no idea
    after looking at your codes and MC setup
    why it wont work.
    I copied just one of the offending images to a new FLA and
    tested it and it works fine...have to get
    back to some client projects but will return to your problem
    later.
    --> Adobe Certified Expert *ACE*
    --> www.mudbubble.com
    --> www.keyframer.com
    BullocksTroy wrote:
    > i'm using version 8, but i just uploaded a version for
    MX:
    >
    > <a target=_blank class=ftalternatingbarlinklarge
    > href="
    http://www.whspcc.com/Banner/CCBannerMX.fla">http://www.whspcc.com/Banner/
    > CCBannerMX.fla</a>
    >

  • Sound in a movie clip malfunctions when play head is moved backward

    Problem summary:
    A sound (stream) placed inside a movie clip that is within another movie clip will start playing continuously when I use the play control to jump around on the main timeline.
    Details:
    I am using Flash CS3 but the same issue occurs with CS6. I've spent quite a bit time to search/research for the issue but didn't find a solution. To demonstrate the problem, I've reduced the flash movie to a very simple structure.
    One the main timeline:
    The first frame has a movie clip (Game MC) and a stop action.
    Following the first frame, there are several frames, mostly empty except some text.
    The last frame has a stop action.
    On the Game MC timeline:
    There is only one frame. On that frame, there is a movie clip (Card MC), and the stop action.
    On the Card MC timeline:
    It starts with 3 blank frames and a stop action.
    Starting at frame 4, a sound (.wav format) is placed and is set to be "stream."
    At the end of this timeline, there is a stop action.
    From Flash CS3, I press Ctrl+Enter to test the movie. The movie stops on frame 1 of the main timeline with the card showing, no sound, as expected. Now I use "." to move the play head forward one frame at a time. No problem. I see the frames after the first frame. Still no sound, as expected. So far so good.
    The problem starts when I use "," to move the play head backward, the sound in the Card MC starts to play, regardless where the play head is, even when the Game MC (thence the Card MC) is not on the stage. Worse, each press of "," will trigger another start of the same sound overlapping with the previous one. And the sound would continue in loops until I close the swf.
    However, the problem will not occur if I place the Card MC directly on the main timeline. It only occurs when it is inside another movie clip (Game MC).
    I need to solve this problem because the full version of the flash card game is to be placed in an HTML page with a javascript based play control, which allows the viewer to jump around in the swf timeline.  
    The fla file is at: https://docs.google.com/file/d/0B_5mgotjr4l5RDZaOGxFeFFWN1U/edit?pli=1
    Am I doing something wrong? Is this a bug in Flash? Any insight will be greatly appreciated.
    Keith

    Thanks. But the problem is that the timeline for the movie clip (Card MC) where the sound is should not have been run because the play head is not on the frame where the Game MC is at (Game MC contains Card MC.) I also put trace actions on various frames on that timeline (for Card MC) and none was invoked. I have also tried to set the sound to "event" or "start". It made no difference.

  • Moving the play head in the main timeline from a button in a movie clip

    I have a movie clip that loads and when it is done playing it has a close button that unloads the movie clip... I want to add code to this button that moves the play head to frame 20 of my main timline using actionScript 3.0

    Tried that but dose not work think its because I am loading the movie this way...
    Play button "playFinal"
    function lastQuestion(event:MouseEvent):void{
         var Info:final1 = new(final1);
         this.stage.addChild(Info);
         Info.x=511
         Info.y=340; }
    So I tried using the Name "Info"
    //example......    MovieClip(Info.root).gotoAndStop(20);
    And I tried the name of the clip in the library "final1"
    //example......    MovieClip(final1.root).gotoAndStop(20);
    Is it because im loading it with actions script instead of having it on the timeline?

  • Can i assign a child state to a movie clip that is already placed on stage

    Hello
    Is it possible to add a child state to a movie clip that is
    already placed on stage,
    i need to do this so i can move the movieclip to the top of
    the display list.
    thanks for the help
    mt

    "The objects i want it to appear above are loaded swf's onto
    the same main stage."
    Aha, this is where things can get confusing. The terminology
    between the Flash Authoring tool and ActionScript is not
    consistent.
    In ActionScript, the Stage is the top most DisplayObject. You
    probably get that.
    In Flash, the canvas that is often referred to as "the stage"
    is not the Stage object of ActionScript, rather the Flash stage is
    a DisplayObject class called MainTimeline (or if you assign a
    document class, it's that class), which is the first and only child
    of the ActionScript Stage object. It's the only child unless, of
    course, you add something else to the ActionScript Stage object at
    runtime... like a loaded swf. ;)
    So in other words, if you are doing anything like this:
    stage.addChild(myLoadedSWF)
    You are actually putting myLoadedSWF above the MainTimeline
    object, which is the entire Flash timeline. There's nothing wrong
    with that, but in this case it means changing the depth of things
    inside the MainTimeline is not going to change the fact that the
    MainTimeline itself is below myLoadedSWF.
    Most likely the simplest solution is to add your loaded SWFs
    to the property "root", not stage. root can refer to different
    things in different places, but most of the time it refers to the
    MainTimeline, and if I had to guess I would say it almost certainly
    does in your case. Note that the "root" property is typed as a
    DisplayObject, not a DisplayObjectContainer, so addChild (which is
    a DisplayObjectContainer method) will not be recognized unless you
    typecast to DisplayObjectContainer or a subclass of
    DisplayObjectContainer, like Sprite or MovieClip:
    MovieClip(root).addChild(myLoadedSWF)
    Also note that, unlike AS2, in AS3 it's very easy to simply
    add your loaded SWF below existing objects you create in Flash. You
    can use addChildAt(obj,0) for instance to add it to the very
    bottom.

Maybe you are looking for