Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.23 / 5.00 3,881 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.93 / 5.00 4,634 ViewsIS there any way to remove a movieclip/object (from an array) from the screen without using removeChild? Thanks!
thanks egg!
Can someone help me with this bit of code i have?
for(j=0;j<i;j++){
BA[j].time--;
if(BA[j].time<=0){
BA[j].alpha -= 1;
}
if(BA[j].alpha < 0)
{
removeChild(BA[j]);
}
} thanks egg!
At 11/6/12 04:22 AM, stegrd wrote: IS there any way to remove a movieclip/object (from an array) from the screen without using removeChild?
No. If something doesn't work, you should not try to find the error in the language.
Most of the time, it's you fault as a programmer that the code is not "working".
You want to ask yourself if something can be more transparent than completely transparent
if(BA[j].alpha < 0)
To do a simple fade, just use a tween engine.
There's one built into As3 (Tween class) which is not as nice as external ones:
http://www.greensock.com/get-started-tweening/
=)
Don't reinvent the wheel.
At 11/6/12 04:22 AM, stegrd wrote: IS there any way to remove a movieclip/object (from an array) from the screen without using removeChild? Thanks!
Dunno about not using removeChild, if you're having problems removing it from the array and the stage at the same time try this:
private function destroy(ob:DisplayObject):void {
if(ob.stage) {
removeChild(ob);
objectsArray.splice(objectsArray.indexOf(ob), 1);
ob = null;
}
}
Call with: destroy(BA[j]);
Of course that means you would have to break out of your for loop or reset the j index.
removeChild(ob);
Sorry, that should be ob.parent.removeChild(ob);
It's more flexible.
if(BA[j].alpha < 0)
Hold on, shouldn't this be if(BA[j].alpha == 0)
At 11/6/12 11:02 AM, ScrumTurd wrote:if(BA[j].alpha < 0)Hold on, shouldn't this be if(BA[j].alpha == 0)
yes, if it's checking that the object isn't visible(in terms of alpha) then equality is better than <
but his fade isn't really a fade, since alpha is 0-1, and off the bat it drops it by 1(100%)
if he wants a fade it should be -= 0.1 or whatever increment, if he just wants it to disappear then he can skip the alpha all together and set a function of just destroying the movieclip
At 11/6/12 04:22 AM, stegrd wrote: IS there any way to remove a movieclip/object (from an array) from the screen without using removeChild? Thanks!
why in the world would you need to do that? Why can't you just removeChild it?
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
but his fade isn't really a fade, since alpha is 0-1, and off the bat it drops it by 1(100%)
I thought that as well, I think he's using reference l (L) instead of 1.