Flash Action Script key Restrictions

Hello, so I do a Pacman game and use the following script for the movement of my character.

onClipEvent (enterFrame) {}

Speed = 10;

If (Key.isDown (Key.LEFT))

{

This ._x-= speed;

_root. Char.gotoAndStop (2);

}

If (Key.isDown (Key.RIGHT))

{

This speed of ._x +=;

_root. Char.gotoAndStop (1);

}

If (Key.isDown (Key.UP))

{

This ._y = speed;

_root. Char.gotoAndStop (3);

}

If (Key.isDown (Key.DOWN))

{

This ._y += speed;

_root. Char.gotoAndStop (4);

}

}

The problem I encounter is that when I press on the right and down keys, or any other two keys that have a diagonal shift, the character goes in that direction.  I want only the character must be able to move to the right, left, up and down.  The _root.char.gotoAndStop (3); part of the script is just for the character is facing in that direction.  Is there a way to limit the number of keys that can be both a? Or to make sure that only the first of the two keys or the second of the two keys pressed is used? If not, is it possible to turn RIGHT and DOWN, press result in diagonal movement which also must face the character in this way? Or stops the character completely? I'd like to mass appreciate any help on this! Thanks in advance!

Walt

One way would be to incorpate "else" of for the last three parolees.  It is therefore the first key determined to be down would be the key that determines the movement.

onClipEvent (enterFrame) {}

Speed = 10;

If (Key.isDown (Key.LEFT))

{

This ._x-= speed;

_root. Char.gotoAndStop (2);

} Else if (Key.isDown (Key.RIGHT)) {}

This speed of ._x +=;

_root. Char.gotoAndStop (1);

} Else if (Key.isDown (Key.UP)) {}

This ._y = speed;

_root. Char.gotoAndStop (3);

} Else if (Key.isDown (Key.DOWN)) {}

This ._y += speed;

_root. Char.gotoAndStop (4);

}

}

Tags: Adobe Animate

Similar Questions

  • Beginner of Flash Action Script 3

    Hi friends,

    I worked as a graphic designer and web and am very interested in learning Flash Action script 3.

    Please guide me to choose a straight path.

    Thanks in advance!

    You will be better to go straight to the AS3... you need not to learn first AS2, and in doing so may confuse learning AS3.

  • Flash action script 3 settings

    How can I change the 3 action script settings? I want to make sure the default scene dimensions are different.

    This isn't really an Actionscript parameter. Open the Properties window for the movie, be sure that it says, 'Document' at the top of the window. In the Properties section, select the icon for key to the right of the dimensions of the stage. Which opens a new window. Here, you can define a new default step size, and then click make default in the lower left corner.

  • Projector is "full screen" look a Cs5.5 Flash action script

    How can I set up a projector for "Full screen" display Flash Cs5.5

    Knowing he already has action script.

    I tried to add FSCommands on top, nothing helps.

    stage.displayState = "fullScreen";

  • In FLex and Flash action script

    Please give me advice.

    I understand just that flex and different flash actionscript?

    If so can you give me the reference material action script in flex?

    ActionScript is the same in flash & flex.   Think that flex is a framework actionscript for the flash player.

  • Flash Action Script hitTest, change of Variable

    Hello! I'm a flash game that is my own point of view on Pacman.  I have to try to make a wall that when a character reaches, the character moves at all.  When I put the code on the wall itself, the character would be hit, then move forward 10 pixels while the key was pressed and spring back 10 pixels when he was in no hurry.  Is it possible to do something completely solid? This is the code that I used before.

    onClipEvent (enterFrame) {}

    If (this.hitTest (_root.char))

    {

    _root. Char._x += 10;

    }

    }

    The code of the character (char) has been

    onClipEvent (enterFrame) {}

    var a_variable = 10;

    If (Key.isDown (Key.LEFT))

    {

    This ._x a_variable-=;

    _root. Char.gotoAndStop (2);

    }

    Else if (Key.isDown (Key.RIGHT))

    {

    This a_variable ._x +=;

    _root. Char.gotoAndStop (1);

    }

    Else if (Key.isDown (Key.UP))

    {

    This ._y = a_variable;

    _root. Char.gotoAndStop (3);

    }

    Else if (Key.isDown (Key.DOWN))

    {

    This ._y += a_variable;

    _root. Char.gotoAndStop (4);

    }

    }

    I wonder if there is a way to define the variable a_variable to 0 when the character hits the wall.

    Thank you.

    ~ Walt

    normally with a hittest positive, you must immediately return the mobile objects to their previous post.

  • How to control the Captivate 4 variable using Flash Action Script 3.0?

    Hi all.

    I'm working on Captivate 4.

    According to my requirement, I need to control externally Captivate system variables in Flash using the AS3 version.

    I found a script somewhere in the forums to control system in AS1 and AS2 variables. But I need them in AS3.

    "this._parent._parent._parent.rdcmndPause = 1;  "

    "this._parent._parent._parent.rdcmndresume = 1;  "

    I tried the same way in the AS3 version but could not do.

    It is an important condition for me.

    How to control variables in Flash AS3 Cp4?

    Kind regards

    Kartik.P

    Use the following code:

    MovieClip (this.root) .rdcmndPause = 1;

    MovieClip (this.root) .rdcmndResume = 1;

    This should solve your problem

  • How copio movimiento of Flash Action Script 3?

    Manual por: crear Flash debo hace despues "Select Edition > tiempo Linea > copy movimiento como ActionScript 3.0" pero en select "edición > Linea tiempo >" no tengo the option "copy as ActionScript 3.0 movimiento.". ¿Solucion?

    This feature no longer exists in flash pro cc.  You can use copy motion as xml in flash pro cc or use flash pro 6 If you want to copy a motion as actionscript

  • using flash action script 3 just won't work to create a link to a url

    If I received a file that has a transparent background button you are looking for linking to url .com, and for the life of me (very probably just too tired) I do not see what to do so that the link to the full animated advertising

    any help would be thank you very much

    You can create a button symbol, in the button Edit mode, keep his place, more and down from executives as white and just specify the affected area by drawing a rect in the fourth.

    Turn on the main timeline and use code extract (in the Windows Menu) to add the code snippet - click here to go to a Web page. Set your url and test the desired animation.

    It should work fine now.

  • Need help with 3.0 in Flash CS5 action script?

    Hi I work with action script 3.0 in flash and our school teacher wants us to create a simple action that allows us to have a clip from the animated film and then we have a stop and a button "play", so when I click on stop the clip stops and when I click on play it moves again. Have tried several times, I get compiler errors. I have my buttons on one layer and my video clip on a separate layer. All I have is 2 buttons. One for the stop and the other to play.

    What I am doing wrong? Here is my code and my mistakes-

    start_btn.onRelease = function() {}


    Polygon.Play ();
    }
    stop_btn.onRelease = function() {}
    Polygon.Stop ();
    }

    Here are my mistakes and if he please be aware that our teacher said to use action script 3 only and no action script 2.

    Scene 1, 'Layer' buttons, image 1, line 1 1120:Access of start_btn of property not defined
    Scene 1, 'Layer' buttons, image 1, line 1 1120:Access of stop_btn of property not defined
    Scene 1, 'Layer' buttons, image 1, line 1 1120:Access of the polygon of property not defined
    Scene 1, 'Layer' buttons, image 1, line 1 1120:Access of the polygon of property not defined

    I think your teacher, or anyone else, gave you sense with ActionScript 2 programming. In AS2, what oyu have here would have worked very well. But in AS3, you use a rather different approach. Your buttons and their instance name, can remain the same. But now in AS3, you must add the following event listeners:

    yourButtonName.addEventListener (MouseEvent.CLICK, yourListenerFunction);

    In your case, you can do one of two things - A) assign a unique to each key listener function or B) assign the same listsner to the two functions:

    (A)

    start_btn.addEventListener (MouseEvent.CLICK, startPolygon);

    stop_btn.addEventListener (MouseEvent.CLICK, stopPolygon);

    function startPolygon(e:MouseEvent):void {}

    Polygon.Play ();

    }

    function stopPolygon(e:MouseEvent):void {}

    Polygon.Stop ();

    }

    (B)

    start_btn.addEventListener (MouseEvent.CLICK, controlPolygon);

    stop_btn.addEventListener (MouseEvent.CLICK, controlPolygon);

    function controlPolygon(e:MouseEvent):void {}

    If (e.target.name == "start_btn") {//Test for the name of the object that sent the CLICK event

    Polygon.Play ();

    } ElseIf (e.target.name == "stop_btn") {}

    Polygon.Stop ();

    }

    }

    When I use multiple buttons that do the same/almost similar things, I support approach B on A, as it keeps me just a simple to process function.

  • I'm on a W7 PC, of FlashProCC. -Have a Z1, jpg in the library. Choose Properties, export for ActionScript and get name Z1, class flash.display.BitmapData - how I introduce in a display by using Action Script 3.0 object?

    I'm on a W7 PC, of FlashProCC. -Have a Z1, jpg in the library. Choose Properties, export for ActionScript and get name Z1, class flash.display.BitmapData - how I introduce in a display by using Action Script 3.0 object?

    var z1:Bitmap = new bitmap;

    Z1. BitmapData = new Z1 (1,1);

    yourDisplayObject.addChild (z1);

  • CC - Flash don't support action script 2

    I have some programs that use action script 2, but when I try and open them in the new version of the CC for flash it says that it does not support AS2

    I have to keep the program on an older computer with a previous version of flash

    It is not cost-effective to update *-any suggestions on what I can do in the new version of CC?

    or CC have access to previous versions of flash?

    Wayne

    Previous through Cloud http://helpx.adobe.com/creative-cloud/help/install-apps.html#previous

  • Timeline navigation in action script 3 based on a key

    Hello!

    I have been using action script 2 for a bit and got decent with it. I'm doing a project that requires a lot of basic key to the timeline navigation. But I can't understand in action script 3?

    In the action script 2 I could just type something like... (Bad example)... Press key "A" Gotoandplay (5)

    But like I said I can't understand things in action script 3. I learned how to use a button on the screen to do that, but it is not the purpose of the project.

    Any help would be much appreciated!

    Thanks in advance!

    You have renamed the event handler function such as the event listener is by specifying / call a function that does not exist

  • Action Script 3.0 for Flash Professional CC running Windows

    Hello world

    I am trying to learn Action Script 3 on Flash Professional CC. The video I'm following courses on Lynda.com and they all speak when referencing an instance of a clip that hits this instance name followed by the (dot) will show a list of available properties for this instance. I see this in action when you watch the video, but when I try properties do not appear. For example, I have a video clip of a circle on my scene and the instance of this clip is named mv_Circle

    When I type the line 1 > mv_Circle.   There should be a list appears displaying the properties, but this does not happen, so I try to guess what the property could be and what its value might be. Example of setting the alpha of this instance I type

    1 > mv_Circle.alpha = 0.5;     but the word alpha does not appear in the supposed list. I'm doing something wrong or I have put in implementation hurt somewhere. My OS is Windows 7 64 bit or victory 8 64-bit. No computer will give me this option.

    I really hope that someone can help me because it drives me crazy. Thank you in advance.

    Dougie

    You can "type" (in other words, explicitly tell Flash of the object class) first mv_Circle:

    var mv_Circle:MovieClip;

    .

    .

    .

    Enter mv_Circle point, you should see the available properties.

  • How t o create breadcrumbs in flash 5 action script 2.0 use cs?

    How t o create breadcrumbs in flash 5 action script 2.0 use cs?

    If the user is throungh go some buttons then there's finally breadcrumbs on the last stage (as it is selected 1, 2 or 3 buttons etc...) and then final should display last used button.

    Besically am looking for bread crumbs. Can anyone know how to create breadcrumbs with the help of the movie clip? or any other code?

    Can someone help me?

    Use swfaddress: http://fcontheweb.com/articles/swfaddress_as2/

Maybe you are looking for