0

I tried to show a random number in three movieclip boxes below(blue, yellow, red) when push button(grey box). to make random numbers I use math.ceil and I keep it in a var. I make 3 var (so I've 3 formula random number). after that, I want to call that 3 var into 3 new var randomly (hasil,hasil2,hasil3). last, i put the 3 new var into random dynamic text. the dynamic text is in three movieclip boxes.

these the formula random number

        mtk = Math.ceil(Math.random()*10);
        mtk1 = Math.ceil(Math.random()*20);
        mtk2 = mtk+mtk1;

these the dynamic text

        mc.jwb1.text = hasil.toString();
        mc.jwb2.text = hasil2.toString();
        mc.jwb3.text = hasil3.toString();

I tried to call the 3 var in 3 random numbers use 2 arrays, but I still confused about how to call them or you have better idea, Please tell me?

enter image description here enter image description here

var mc:jwb = new jwb();

var mtk:Number;
var mtk1:Number;
var mtk2:Number;

var hasil:int;
var hasil2:int;
var hasil3:int;

btn.addEventListener(MouseEvent.CLICK, button);
function button(e:MouseEvent):void{
    addChild(mc);
}

Batas_mc.addEventListener(Event.ENTER_FRAME, batas);
    function batas(e:Event):void{
        mc.x = 270;
        mc.y = 130;

        mtk = Math.ceil(Math.random()*10);
        mtk1 = Math.ceil(Math.random()*20);
        mtk2 = mtk+mtk1;

        //Array object acak
            var P:Array = [mtk, mtk1, mtk2];
            var M:Array = [hasil, hasil2, hasil3];

            while (M.length){

                // Get the last MovieClip and remove it from the list.
                var Batumc2:MovieClip = M.pop();

                // Produce a random Point.
                var anIndex:int = Math.random() * P.length;
                var aPo = P[anIndex];

                // Remove the selected Point from its list.
                P.splice(anIndex, 1);

                // Move the selected MovieClip to the selected Point coordinates.
                Batumc2 = aPo;
            }

        mc.jwb1.text = hasil.toString();
        mc.jwb2.text = hasil2.toString();
        mc.jwb3.text = hasil3.toString();
    }
Tamara
  • 23
  • 7
  • Sorry, not clear what are you trying to achieve, not clear what is the problem either. – Organis Sep 21 '19 at 19:29
  • in short, I want to call 3 formula random numbers, in 3 dynamic text randomly. and those dynamic text is in three movieclip boxes @Organis – Tamara Sep 23 '19 at 02:22
  • 1
    So, why can't you just **mc.jwb1.text = String(int(10 * Math.random()));** for all three? – Organis Sep 23 '19 at 19:14

0 Answers0