-
Senior Member
[F8] Managing MCs via Arrays
OK I am needing to update some of my techniques for managing lots of movieClip objects... I have seen somewhere some people will create the clip then push it into an Array.
Then, somehow you can control it from the array and delete it. How do I go about deleting it from the array such that it also deletes the entire movieClip?
My initial tests aren't working.
~Ray, the advanced Noob
(Will post code soon)
-
this should work
PHP Code:
var mcs:Array = new Array();
function addMc(){ var z:Number = _root.getNextHighestDepth();//unique depth and name ID var mc = _root.createEmptyMovieClip("mcClp"+z,z) ;//movieClip with the instance name "mc"+z and a shortcut to mc mcs.push( mc );//add the link to the array mc.lineStyle(2,0xff0000,100); mc.moveTo(0, 0); mc.lineTo(128, 0); mc.lineTo(128, 64); mc.lineTo(0, 64); mc.lineTo(0, 0); trace(z+"length: "+mcs.length); } function removeMc(nr){ mcs[nr].removeMovieClip(); mcs.splice(nr,1);//remove the array container }
for (var i:Number = 0;i<6;i++){ addMc(); mcs[i]._x = i*(128+8); }
you basicly create pointers or shortcuts to the actual movieClip object - that´s at least the way I know how to do it in AS1/2.
In AS3 you then actually can initiate a real MovieClip or sprite inside a Array container but not in AS2.
Btw. a very effecient way to store automaticly all movieClips from _root level in a array is:
PHP Code:
var mcs:Array = new Array(); for (mc in _root){//loop through all elements in the _root level if ( typeof(eval(mc)) == "movieclip"){ mcs.push( eval(mc) );//add shortcut to array } }
that would be basicly the same except that it catches the movieClips from the stage automatily in a array.
This can be usefull to analyze the movieClips using a clipping grid or some other mechanics that require to inspect the positions of all movieClips and sizes ahead.
-
Senior Member
Thank you Render. This is basically what I was trying but killing off content doesn't work. Example:
Creating and "storing" the clips:
clip = this.SCROLL_BATTLERS.viewer_mc.content_mc.createEm ptyMovieClip("ROW" + row1, depth++);
chatInBattleObjects.push(clip);
Testing to see if the reference still works (this works!):
chatInBattleObjects[0]._xscale = 200;
Trying to remove the clips, NONE of these work:
chatInBattleObjects[0].unloadMovie();
chatInBattleObjects[0].removeMovieClip();
delete chatInBattleObjects[0];
Any ideas?
-
ism
sorry. misread the post.
Code:
chatInBattleObjects[0].removeMovieClip();
should work. try tracing the value;
Code:
trace("mc="+chatInBattleObjects[0]);
one you remove the mc you can delete the zero array reference by shifting it;
Code:
chatInBattleObjects.shift();
Last edited by BlinkOk; 09-11-2008 at 07:27 PM.
Graphics Attract, Motion Engages, Gameplay Addicts
XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro
-
Senior Member
Trace shows:
_level0.SCROLL_BATTLERS.viewer_mc.content_mc.ROW0
-
Senior Member
I think I know what's going on. I've got a mix of movieclips and textfields in the array. So textfields aren't being removed unless I use removeTextField()
Thank you for your help. It's all good now.
Last edited by Ray Beez; 09-11-2008 at 11:07 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|