Determining the movieclip assigned to a variable in an array AS3
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
add a comment |
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
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
add a comment |
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
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
arrays for-loop actionscript-3
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
thats what I wanted, thank you very much
– Koden
Nov 27 '18 at 9:43
add a comment |
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
There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name withif (block is Rblock)
(in fact you check if this block is eitherRblock
or a descendant ofRblock
this way, but normally you only check against a leaf class, so this is irrelevant).
– Vesper
Nov 26 '18 at 15:19
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
thats what I wanted, thank you very much
– Koden
Nov 27 '18 at 9:43
add a comment |
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
thats what I wanted, thank you very much
– Koden
Nov 27 '18 at 9:43
add a comment |
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
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
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
add a comment |
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
add a comment |
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
There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name withif (block is Rblock)
(in fact you check if this block is eitherRblock
or a descendant ofRblock
this way, but normally you only check against a leaf class, so this is irrelevant).
– Vesper
Nov 26 '18 at 15:19
add a comment |
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
There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name withif (block is Rblock)
(in fact you check if this block is eitherRblock
or a descendant ofRblock
this way, but normally you only check against a leaf class, so this is irrelevant).
– Vesper
Nov 26 '18 at 15:19
add a comment |
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
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
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 withif (block is Rblock)
(in fact you check if this block is eitherRblock
or a descendant ofRblock
this way, but normally you only check against a leaf class, so this is irrelevant).
– Vesper
Nov 26 '18 at 15:19
add a comment |
There are traits, namely class names, or also a common name of a superclass, you can perform checks against class name withif (block is Rblock)
(in fact you check if this block is eitherRblock
or a descendant ofRblock
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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