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

Problem with 2 rows arrays

Explorer ,
Aug 22, 2021 Aug 22, 2021

Copy link to clipboard

Copied

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]

Views

186

Translate

Translate

Report

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 ,
Aug 23, 2021 Aug 23, 2021

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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 ,
Aug 23, 2021 Aug 23, 2021

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Aug 23, 2021 Aug 23, 2021

Copy link to clipboard

Copied

i thought you indicated the names are in chromo2?

Votes

Translate

Translate

Report

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 ,
Aug 23, 2021 Aug 23, 2021

Copy link to clipboard

Copied

Yes, the names are in chromo2. But I try alert (chromo2[2]); and it gives me the 3rd in the chromo2 list and not the 3rd sorted according to chromo1. What syntax should I use to retrieve the name in chromo2 based on the sorting done by chromo1?
Thanks for your help.

Votes

Translate

Translate

Report

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 ,
Aug 24, 2021 Aug 24, 2021

Copy link to clipboard

Copied

Here is a screenshot I get with the following code. The clips are not in Y-order. Where is my mistake please?

app = this;
var chromo1 = [app.myClip0.y, app.myClip1.y, app.myClip2.y, app.myClip3.y];
var chromo2 = [app.myClip0, app.myClip1, app.myClip2, app.myClip3];


sortF(chromo1,chromo2);

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;



app.texte.text = "order of clips = "+[chromo2];
app.texte1.text = "clip0.y = "+app.myClip0.y;
app.texte2.text = "clip1.y = "+app.myClip1.y;
app.texte3.text = "clip2.y = "+app.myClip2.y;
app.texte4.text = "clip3.y = "+app.myClip3.y;
}}}}

Votes

Translate

Translate

Report

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 ,
Aug 24, 2021 Aug 24, 2021

Copy link to clipboard

Copied

sortF(chromo1,chromo2);

console.log(chromo2[2]);

 

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

Votes

Translate

Translate

Report

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 ,
Aug 24, 2021 Aug 24, 2021

Copy link to clipboard

Copied

This works. Many thanks to you.

Votes

Translate

Translate

Report

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 ,
Aug 24, 2021 Aug 24, 2021

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

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