Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

two doubts

Explorer ,
Dec 19, 2015 Dec 19, 2015

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

TOPICS
ActionScript
575
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2015 Dec 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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2015 Dec 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2015 Dec 19, 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2015 Dec 19, 2015

kglad escreveu:

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);

}

Hello kglad, the request itself was a function that determines the appearance of a moveclip ... I think I may have understood the wrong way, I will try to give an example. Let's say I put the object converted into moveclip in one spot of the stage, and a role in actions that determines its Alpha (increasing its Alpha her to stay visible). The request is that the object appears on the site I want only.

To do something like this ...


var luck:Number = 2;


if (luck == 1) {

    // appear object

}


if(luck == 2) {

  // No acnion.

}


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2015 Dec 20, 2015


  1. var luck:Number = 2
  2.  
  3.  
  4. if (luck == 1) { 
  5.    addChild(appearObject);
  6.  
  7.  
  8.  
  9. if(luck == 2) { 
  10.   // No acnion. 
  11.  
  12.  
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 21, 2015 Dec 21, 2015

So if I can add the name in the MovieClip () to add the object?

addChild (moveclipname);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 21, 2015 Dec 21, 2015
LATEST

no, not the name.  it has to be a reference to the movieclip.

so you could use:

addChild(getChildByName(movieclipname));

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