Skip to main content
Inspiring
August 22, 2021
Question

Problem with 2 rows arrays

  • August 22, 2021
  • 1 reply
  • 730 views

Hello,
In Animate HTML5, I want to associate a createjs.Tween to a clip according to its Y ordinate. The ordinate will be random. For this, I have created 2 arrays. The first table allows to sort the Y ordinates of the clips. The second table contains the names of the clips.
How can we sort the names of the clips according to their ordinate given by the first table?
The code below does not work: it indicates that it is impossible to assign the "tweenjs" property to the ordinate of a clip.

 

function compare(a, b)
{
    return a - b;
};

var chromo1 = [this.myClip0.y, this.myClip1.y, this.myClip2.y, this.myClip2.y];
var chromo2 = [this.myClip0, this.myClip1, this.myClip2, this.myClip3];
chromo1.sort(compare);

createjs.Tween.get(chromo1[1])
.to({x:378, y: 102},4000,createjs.Ease.circOut)

 

Thanks for any help.

[link removed by moderator]

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    August 23, 2021

    sortF(chromo1,chromo2);

    // chromo2 is now sorted per the values in chromo1

     

    function sortF(a,b){
    if(a.length!=b.length){
    return
    }
    for(var i=0;i<a.length-1;i++){
    for(var j=i+1;j<a.length;j++){
    if(a[i]>a[j]){
    var temp = b[i];
    b[i] = b[j];
    b[j] = temp;
    }
    }
    }
    }

     

    Inspiring
    August 23, 2021

    Thank you for your answer but my skills are too limited I can't find how to get the name of the clip to associate it with createjs.tween.

    kglad
    Community Expert
    Community Expert
    August 23, 2021

    i thought you indicated the names are in chromo2?