Skip to main content
Participant
November 26, 2023
質問

How can I use "setChildIndex" with animate 2015 for chose the index of movieclip

  • November 26, 2023
  • 返信数 1.
  • 157 ビュー

Hello,

I'm French an I try to convert my old AS3 sciences App to HTML5 canvas with animate 2015.

I made an exemple for explain my probreme. I m trying to use "randel" for chose the z-index of movieclip

I cant't attach the .fla

You can download here : http://svt.riffiod.fr/Z_index.fla

I past the code here

"

this.stop();

let root = this;

function randel (tab){
var r = Math.round (Math.random() * (tab.length - 1));
var rec = tab[r];
tab.splice (r, 1);
return rec;
}
//make array with number 1 to 4
var MyArray = new Array();
for (var i=0; i<5; i++){
MyArray[i] = (i+1);
}
//
while (MyArray.length){
var MyIndex = new Array();
for (var j=0; j<5; j++){
MyIndex[j] = 2 + randel(MyArray);
}
}

root.setChildIndex(root.MovieClip01, MyIndex[0]);
root.setChildIndex(root.MovieClip02, MyIndex[1]);
root.setChildIndex(root.MovieClip03, MyIndex[2]);
root.setChildIndex(root.MovieClip04, MyIndex[3]);

"

but the movieClip stay at the same index that I put on the root (stage).

How I can do for have a randel z-index postition for different movieclip?

Thanks

Romain RIFFIOD

    このトピックへの返信は締め切られました。

    返信数 1

    kglad
    Community Expert
    Community Expert
    November 26, 2023

    MyArray contains numbers 1 to 5 so your indexes are out of range. ie, change your for-loops so they contain 4 elements, not 5.

     

    p.s. i'm not sure what randel is supposed to do, but if it's a randomizer, it's not a good one.

     

    Participant
    November 26, 2023

    Thanks,

    but that dosen't work.

    I try this too, bue that don't want to work to :

    "

    this.stop();

    let root = this;

    function randel (tab){
    var r = Math.round (Math.random() * (tab.length - 1));
    var rec = tab[r];
    tab.splice (r, 1);
    return rec;
    }
    //make array with number 1 to 4
    var MyArray = new Array();
    for (var i=0; i<4; i++){
    MyArray[i] = (i+1);
    }
    //
    while (MyArray.length){
    var MyIndex = new Array();
    for (var j=0; j<4; j++){
    MyIndex[j] = 2 + randel(MyArray);
    }
    }

    root.setChildIndex(root.MovieClip01, root.numChildren + MyIndex[0]);
    root.setChildIndex(root.MovieClip02, root.numChildren + MyIndex[1]);
    root.setChildIndex(root.MovieClip03, root.numChildren + MyIndex[2]);
    root.setChildIndex(root.MovieClip04, root.numChildren + MyIndex[3]);"

    I can't anderstand the probleme...

    kglad
    Community Expert
    Community Expert
    November 26, 2023

    you changed your setChildIndex code so the indices are again, out of range.

     

    what are you trying to do?  randomize the depth of those 4 movieclips?