Skip to main content
Participating Frequently
April 15, 2013
Answered

Newbie needs some help. i need to show a MC on the stage in 4 random positions?

  • April 15, 2013
  • 1 reply
  • 788 views

i am new to actionscript and need some help with showing my MC in 4 places on the stage (topleft, topright, bottomleft, bottomright) all one after the other with a 2 second delay between them.

if any one has any actionscript 3.0 on how to do this youd be a life saver

This topic has been closed for replies.
Correct answer kglad

the topleft etc are not random positions but, if MC has reg point at the top left:

addChild(MC);

MC.x=MC.y=0;

var positionA:Array=[[stage.stageWidth-MC.width,0],[0,stage.stageHeight-MC.height],[stage.stageWidth-MC-width,stage.stageHeight-MC.height]];

var t:Timer=new Timer(2000,3);

t.addEventListener(TimerEvent.TIMER,f);

t.start();

function f(e:TimerEvent):void{

MC.x=positionA[t.currentCount][0];

MC.y=positionA[t.currentCount][1];

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 15, 2013

the topleft etc are not random positions but, if MC has reg point at the top left:

addChild(MC);

MC.x=MC.y=0;

var positionA:Array=[[stage.stageWidth-MC.width,0],[0,stage.stageHeight-MC.height],[stage.stageWidth-MC-width,stage.stageHeight-MC.height]];

var t:Timer=new Timer(2000,3);

t.addEventListener(TimerEvent.TIMER,f);

t.start();

function f(e:TimerEvent):void{

MC.x=positionA[t.currentCount][0];

MC.y=positionA[t.currentCount][1];

}

Participating Frequently
April 15, 2013

okay so i understand the timer and that the function calls the array?

but i dont really understand the array? could you explain it? or what i need to change ion the array to customise it to my project?

kglad
Community Expert
Community Expert
April 15, 2013

nothing needs to be changed if MC reg point is at its top-left.

the array positions MC at the topleft, etc of your stage.  copy and paste the code and try it.