Highlighted

moving multiple symbols across stage as3

New Here ,
Dec 28, 2019

Copy link to clipboard

Copied

Hi,

I am working on a simple video game in which I need to move 50+ symbols across the stage with the same speed. I would like to use a single as3 command with which I can target all symbols at the same time. Currently I have added the symbols one by one:

Code snippets for moving symbols to the right:

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_3);stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_3);

 function fl_MoveInDirectionOfKey_3(event:Event)
{
    if  (rightPressed) {        mc1.x = 5;        mc2.x = 5;        mc3.x = 5;        mc4.x = 5; 
        and so on....,
}

What can I do to apply the function to all mc symbols in one go?

Thank you!

TOPICS
ActionScript

Views

320

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

moving multiple symbols across stage as3

New Here ,
Dec 28, 2019

Copy link to clipboard

Copied

Hi,

I am working on a simple video game in which I need to move 50+ symbols across the stage with the same speed. I would like to use a single as3 command with which I can target all symbols at the same time. Currently I have added the symbols one by one:

Code snippets for moving symbols to the right:

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_3);stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_3);

 function fl_MoveInDirectionOfKey_3(event:Event)
{
    if  (rightPressed) {        mc1.x = 5;        mc2.x = 5;        mc3.x = 5;        mc4.x = 5; 
        and so on....,
}

What can I do to apply the function to all mc symbols in one go?

Thank you!

TOPICS
ActionScript

Views

321

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 28, 2019 0
Adobe Community Professional ,
Dec 28, 2019

Copy link to clipboard

Copied

Did you mean: mc1.x = mc1.x+5;?

 

That aside, if you are making the movieclips with code you could add them to a container movieclip, and then jusst move the container each frame.

 

If the objects are supposed to loop, that would make it a bit harder, but you could have two container movieclips that are copies of each other, and as the leftmost inner movieclip goes off the right of the screen, you would move that container straight to the left of the screen minus the width of the container.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2019 0
New Here ,
Dec 28, 2019

Copy link to clipboard

Copied

Hi, 

thank you. yes, I meant: 

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_3);stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_3);

 function fl_MoveInDirectionOfKey_3(event:Event)
{
    if  (rightPressed) {        mc1.x = +5;        mc2.x = +5;        mc3.x = +5;        mc4.x = +5; 
        and so on....,
}

 

I have not creating the symbols with code. They are animated symbolds that I have designed in adobe animate.

How would I go about adding them to a container? 

Thank you. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2019 0
JudithKr LATEST
New Here ,
Dec 28, 2019

Copy link to clipboard

Copied

The full code for this problem is:
 
var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
 
mc1.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_3);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_3);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_3);
 
function fl_MoveInDirectionOfKey_3(event:Event)
 
if (rightPressed) {
mc1.x += 10;
mc2.x  += 10;
mc3.x += 10;
mc4.x += 10;
mc5.x += 10;
......
}}
 
I am not trying to loop the mcs. I just need them to move across the stage together. 
Thank you.
 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2019 0