Copy link to clipboard
Copied
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
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];
}
Copy link to clipboard
Copied
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];
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
had to edit teh code just a bit because of some small punctuation errors, but this is great stuff!
currently goes top left bottom left and bottom right with a 2 second delay which is fantastic!
how do i edit the position of the MC? maybe add more positions where it shows on the stage?
sorry for the questions i have to show my understanding in my school project
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];
}
f;
Copy link to clipboard
Copied
to show more positions, you would edit positionA to add more x,y positions. each element of positionA is an array that contains an x,y position.
and, you edit the timer t so it makes more calls to f.
but, if you want to display your movieclip in random positions anywhere on stage, use:
var t:Timer=new Timer(2000,0);
t.addEventListener(TimerEvent.TIMER,f);
t.start();
function f(e:TimerEvent):void{
MC.x=Math.floor(Math.random()*(stage.stageWidth-MC.width))
MC.y=Math.floor(Math.random()*(stage.stageHeight-MC.height))
}
Copy link to clipboard
Copied
this is great! thanks very much
sooo say if i needed the MC to randomly go into just the 4 corners of the stage instead of all over, would i just put some coordinates in the bracets of the math.random
like this?
Math.random(x=?,y=?)
or would they be needed from the array? like this?
function f(e:TimerEvent):void{
MC.x=Math.floor(Math.random()*(PositionA))
MC.y=Math.floor(Math.random()*(PositionA))
}
Copy link to clipboard
Copied
no, if you want to specify several locations, add the locations to an array like positionA.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now