Skip to main content
Inspiring
December 19, 2015
Question

two doubts

  • December 19, 2015
  • 1 reply
  • 635 views

1. What role can be attributed to add / remove an object? I believe it is necessary to convert it to MoveClip ... But I have not found an exact function.
I saw some posts where users use "removeChildren" But I do not know if that's what my question is.
Could anyone help me with these little problems? Grateful.


2. How can I be assigning a random selection function? I will give an example, but I do not think that works in actionscript this way.


var luck = random(2);

if(luck == 1) {

    action;

}

if(luck == 2) {

    action2;

}

...

If the function would be called with the event of a "draw" between the numbers 1 and 2, which are predefined in the random variable.
Could anyone help me? Grateful

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
December 19, 2015

1.  what's your question?

2. again, i'm not sure what you're asking.  but if you want to call different functions, you can use:

var luck:int=Math.ceil(2*Math.random());

this['F'+luck]();

function F1():void{

// do whatever

}

function F2():void{

//do whatever else

}

vvvverTAuthor
Inspiring
December 19, 2015

The question of the issue one is exactly "What function should I use to add or remove a MoveClip?"
Let's say our moveclip has the name "test" the goal is to make the object appear in one of two random functions ... So I wonder what code can be using for this function.

kglad
Community Expert
Community Expert
December 20, 2015

a movieclip doesn't appear in a function.  you could create a function to make a movieclip appear.

and you could make the movieclip appear at a random position on stage.  eg, for mobieclips with upper left reg point:

function addAtRandomF(mc:MovieClip):void{

addChild(mc);

mc.x=Math.random()*(Stage.stageWidth-mc.width);

mc.y=Math.random()*(Stage.stageHeight-mc.height);

}