Determining the movieclip assigned to a variable in an array AS3












0















Please forgive my terminology, Im not educated on the proper.



Lets say I have multiple movieclip variables



var rblock1:MovieClip = new Rblock();
var rblock2:MovieClip = new Rblock();
var rblock3:MovieClip = new Rblock();
var yblock1:MovieClip = new Yblock();
var yblock2:MovieClip = new Yblock();
var yblock3:MovieClip = new Yblock();


I have them added to an array



var blockarray:Array = new Array(rblock1, rblock2, rblock3, yblock1, yblock2, yblock3);
var block


I want to create a for loop with an if statement that triggers if a variable is Rblock and not Yblock, for example



for each (block in blockarray)
{

if (block==Rblock)
{
trace("rblock");
}

}


The issue is that obviously "if (block==Rblock)" doesnt work.
How should this be written?










share|improve this question

























  • Case sensitivity.

    – Organis
    Nov 26 '18 at 2:38











  • no im not trying to declare the clip, im trying to declare the class, the class is Rblock, the clip is rblock

    – Koden
    Nov 26 '18 at 2:40











  • i have edited the question to avoid the confusion that you were right to assume

    – Koden
    Nov 26 '18 at 2:42






  • 1





    To check if an instance belongs to a class you use if (block is Rblock) statement.

    – Organis
    Nov 26 '18 at 6:06
















0















Please forgive my terminology, Im not educated on the proper.



Lets say I have multiple movieclip variables



var rblock1:MovieClip = new Rblock();
var rblock2:MovieClip = new Rblock();
var rblock3:MovieClip = new Rblock();
var yblock1:MovieClip = new Yblock();
var yblock2:MovieClip = new Yblock();
var yblock3:MovieClip = new Yblock();


I have them added to an array



var blockarray:Array = new Array(rblock1, rblock2, rblock3, yblock1, yblock2, yblock3);
var block


I want to create a for loop with an if statement that triggers if a variable is Rblock and not Yblock, for example



for each (block in blockarray)
{

if (block==Rblock)
{
trace("rblock");
}

}


The issue is that obviously "if (block==Rblock)" doesnt work.
How should this be written?










share|improve this question

























  • Case sensitivity.

    – Organis
    Nov 26 '18 at 2:38











  • no im not trying to declare the clip, im trying to declare the class, the class is Rblock, the clip is rblock

    – Koden
    Nov 26 '18 at 2:40











  • i have edited the question to avoid the confusion that you were right to assume

    – Koden
    Nov 26 '18 at 2:42






  • 1





    To check if an instance belongs to a class you use if (block is Rblock) statement.

    – Organis
    Nov 26 '18 at 6:06














0












0








0








Please forgive my terminology, Im not educated on the proper.



Lets say I have multiple movieclip variables



var rblock1:MovieClip = new Rblock();
var rblock2:MovieClip = new Rblock();
var rblock3:MovieClip = new Rblock();
var yblock1:MovieClip = new Yblock();
var yblock2:MovieClip = new Yblock();
var yblock3:MovieClip = new Yblock();


I have them added to an array



var blockarray:Array = new Array(rblock1, rblock2, rblock3, yblock1, yblock2, yblock3);
var block


I want to create a for loop with an if statement that triggers if a variable is Rblock and not Yblock, for example



for each (block in blockarray)
{

if (block==Rblock)
{
trace("rblock");
}

}


The issue is that obviously "if (block==Rblock)" doesnt work.
How should this be written?










share|improve this question
















Please forgive my terminology, Im not educated on the proper.



Lets say I have multiple movieclip variables



var rblock1:MovieClip = new Rblock();
var rblock2:MovieClip = new Rblock();
var rblock3:MovieClip = new Rblock();
var yblock1:MovieClip = new Yblock();
var yblock2:MovieClip = new Yblock();
var yblock3:MovieClip = new Yblock();


I have them added to an array



var blockarray:Array = new Array(rblock1, rblock2, rblock3, yblock1, yblock2, yblock3);
var block


I want to create a for loop with an if statement that triggers if a variable is Rblock and not Yblock, for example



for each (block in blockarray)
{

if (block==Rblock)
{
trace("rblock");
}

}


The issue is that obviously "if (block==Rblock)" doesnt work.
How should this be written?







arrays for-loop actionscript-3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 2:54







Koden

















asked Nov 26 '18 at 2:35









KodenKoden

12311




12311













  • Case sensitivity.

    – Organis
    Nov 26 '18 at 2:38











  • no im not trying to declare the clip, im trying to declare the class, the class is Rblock, the clip is rblock

    – Koden
    Nov 26 '18 at 2:40











  • i have edited the question to avoid the confusion that you were right to assume

    – Koden
    Nov 26 '18 at 2:42






  • 1





    To check if an instance belongs to a class you use if (block is Rblock) statement.

    – Organis
    Nov 26 '18 at 6:06



















  • Case sensitivity.

    – Organis
    Nov 26 '18 at 2:38











  • no im not trying to declare the clip, im trying to declare the class, the class is Rblock, the clip is rblock

    – Koden
    Nov 26 '18 at 2:40











  • i have edited the question to avoid the confusion that you were right to assume

    – Koden
    Nov 26 '18 at 2:42






  • 1





    To check if an instance belongs to a class you use if (block is Rblock) statement.

    – Organis
    Nov 26 '18 at 6:06

















Case sensitivity.

– Organis
Nov 26 '18 at 2:38





Case sensitivity.

– Organis
Nov 26 '18 at 2:38













no im not trying to declare the clip, im trying to declare the class, the class is Rblock, the clip is rblock

– Koden
Nov 26 '18 at 2:40





no im not trying to declare the clip, im trying to declare the class, the class is Rblock, the clip is rblock

– Koden
Nov 26 '18 at 2:40













i have edited the question to avoid the confusion that you were right to assume

– Koden
Nov 26 '18 at 2:42





i have edited the question to avoid the confusion that you were right to assume

– Koden
Nov 26 '18 at 2:42




1




1





To check if an instance belongs to a class you use if (block is Rblock) statement.

– Organis
Nov 26 '18 at 6:06





To check if an instance belongs to a class you use if (block is Rblock) statement.

– Organis
Nov 26 '18 at 6:06












2 Answers
2






active

oldest

votes


















1














You apparently want to check if a block is red or yellow by checking against its class name. You can do it with this:



if (block is Rblock) {...} // yes, red





share|improve this answer
























  • thats what I wanted, thank you very much

    – Koden
    Nov 27 '18 at 9:43



















0














I have figured out a work around not really a perfect solution, which will only work for certain scenarios...



if each class has a unique trait you can identify it that way, for example...



if all variables defined by the Rblock class are wider than the Yblock class you could say



if (block.width>x) { trace(Rblock); }


Like I said this is only a work around though and only works for movieclip variables defined by classes that are different, if anyone has the actual solution please post






share|improve this answer
























  • There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name with if (block is Rblock) (in fact you check if this block is either Rblock or a descendant of Rblock this way, but normally you only check against a leaf class, so this is irrelevant).

    – Vesper
    Nov 26 '18 at 15:19











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474082%2fdetermining-the-movieclip-assigned-to-a-variable-in-an-array-as3%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You apparently want to check if a block is red or yellow by checking against its class name. You can do it with this:



if (block is Rblock) {...} // yes, red





share|improve this answer
























  • thats what I wanted, thank you very much

    – Koden
    Nov 27 '18 at 9:43
















1














You apparently want to check if a block is red or yellow by checking against its class name. You can do it with this:



if (block is Rblock) {...} // yes, red





share|improve this answer
























  • thats what I wanted, thank you very much

    – Koden
    Nov 27 '18 at 9:43














1












1








1







You apparently want to check if a block is red or yellow by checking against its class name. You can do it with this:



if (block is Rblock) {...} // yes, red





share|improve this answer













You apparently want to check if a block is red or yellow by checking against its class name. You can do it with this:



if (block is Rblock) {...} // yes, red






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 15:17









VesperVesper

16.8k42849




16.8k42849













  • thats what I wanted, thank you very much

    – Koden
    Nov 27 '18 at 9:43



















  • thats what I wanted, thank you very much

    – Koden
    Nov 27 '18 at 9:43

















thats what I wanted, thank you very much

– Koden
Nov 27 '18 at 9:43





thats what I wanted, thank you very much

– Koden
Nov 27 '18 at 9:43













0














I have figured out a work around not really a perfect solution, which will only work for certain scenarios...



if each class has a unique trait you can identify it that way, for example...



if all variables defined by the Rblock class are wider than the Yblock class you could say



if (block.width>x) { trace(Rblock); }


Like I said this is only a work around though and only works for movieclip variables defined by classes that are different, if anyone has the actual solution please post






share|improve this answer
























  • There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name with if (block is Rblock) (in fact you check if this block is either Rblock or a descendant of Rblock this way, but normally you only check against a leaf class, so this is irrelevant).

    – Vesper
    Nov 26 '18 at 15:19
















0














I have figured out a work around not really a perfect solution, which will only work for certain scenarios...



if each class has a unique trait you can identify it that way, for example...



if all variables defined by the Rblock class are wider than the Yblock class you could say



if (block.width>x) { trace(Rblock); }


Like I said this is only a work around though and only works for movieclip variables defined by classes that are different, if anyone has the actual solution please post






share|improve this answer
























  • There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name with if (block is Rblock) (in fact you check if this block is either Rblock or a descendant of Rblock this way, but normally you only check against a leaf class, so this is irrelevant).

    – Vesper
    Nov 26 '18 at 15:19














0












0








0







I have figured out a work around not really a perfect solution, which will only work for certain scenarios...



if each class has a unique trait you can identify it that way, for example...



if all variables defined by the Rblock class are wider than the Yblock class you could say



if (block.width>x) { trace(Rblock); }


Like I said this is only a work around though and only works for movieclip variables defined by classes that are different, if anyone has the actual solution please post






share|improve this answer













I have figured out a work around not really a perfect solution, which will only work for certain scenarios...



if each class has a unique trait you can identify it that way, for example...



if all variables defined by the Rblock class are wider than the Yblock class you could say



if (block.width>x) { trace(Rblock); }


Like I said this is only a work around though and only works for movieclip variables defined by classes that are different, if anyone has the actual solution please post







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 3:16









KodenKoden

12311




12311













  • There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name with if (block is Rblock) (in fact you check if this block is either Rblock or a descendant of Rblock this way, but normally you only check against a leaf class, so this is irrelevant).

    – Vesper
    Nov 26 '18 at 15:19



















  • There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name with if (block is Rblock) (in fact you check if this block is either Rblock or a descendant of Rblock this way, but normally you only check against a leaf class, so this is irrelevant).

    – Vesper
    Nov 26 '18 at 15:19

















There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name with if (block is Rblock) (in fact you check if this block is either Rblock or a descendant of Rblock this way, but normally you only check against a leaf class, so this is irrelevant).

– Vesper
Nov 26 '18 at 15:19





There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name with if (block is Rblock) (in fact you check if this block is either Rblock or a descendant of Rblock this way, but normally you only check against a leaf class, so this is irrelevant).

– Vesper
Nov 26 '18 at 15:19


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474082%2fdetermining-the-movieclip-assigned-to-a-variable-in-an-array-as3%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'