A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] Managing MCs via Arrays

  1. #1
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793

    [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)

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    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.pushmc );//add the link to the array
        
        
    mc.lineStyle(2,0xff0000,100);
        
    mc.moveTo(00);
        
    mc.lineTo(1280);
        
    mc.lineTo(12864);
        
    mc.lineTo(064);
        
    mc.lineTo(00);
        
    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.

  3. #3
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    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?

  4. #4
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    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

  5. #5
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    Trace shows:

    _level0.SCROLL_BATTLERS.viewer_mc.content_mc.ROW0

  6. #6
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center