A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: swap MovieClip with another duplicated clip

  1. #1
    Senior Member
    Join Date
    Aug 2001
    Location
    New York City
    Posts
    409

    swap MovieClip with another duplicated clip

    I am trying to duplicate a MovieClip on the stage...then replace another clip on the stage with the duplicated clip...I almost have it . . . can anyone offer some guidance as to why this isn;t working...or maybe there is a better way.

    PHP Code:
    red.duplicateMovieClip("rectangle"1);
    rectangle._xscale 200;
    //
    MovieClip.prototype.swapClip = function(idName) {
        var 
    obj = {_x:this._x_y:this._y_xscale:this._xscale_yscale:this._yscale_rotation:this._rotation_visible:this._visible_alpha:this._alphaidName:idName};
        
    this._parent.attachMovie(idNamethis._namethis.getDepth(), obj);
    };
    ASSetPropFlags(MovieClip.prototype, ["swapClip"], 1);
    holder.swapClip("rectangle");
    //MovieClip instance named my_mc will be replaced by another clip 

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Flash will only let you place one instance per _level per timeline. That means any clip loaded into an occupied level, replaces the currently loaded instance with itself. This is only dangerous if the currently loaded clip has event listeners or intervals tied to it. They need to be removed and cleared as needed before replacement.

    So why not give the clip you would be duplicating a linkage name and instead of duplicating, use attachMovie right on the clip to be replaced.

    Say you want to duplicate apple and then replace orange with the new copy. Instead, just replace orange by attaching a new instance of apple.

    So if you had a holder clip for the orange but you didn't know what level orange was on:
    orangeHolder.attachMovie("appleLinkage", "newApple_mc",orangeHolder.orange.getDepth());

    That will replace orange with a new copy of apple. In case you wanted the new apple to inherit the transformations of the original apple, you could capture and apply its transformation matrix.

  3. #3
    Senior Member
    Join Date
    Aug 2001
    Location
    New York City
    Posts
    409
    ...Is there any way you can think of without using attachMovie ?
    I am trying NOT to use items from the library, it's messing
    with my preloader . . .or can I use attachMovie if the MC lives on the stage ?

  4. #4
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Unfortunately, you cannot move a clip, duplicated or not, into or out of another timeline/movieclilp.

    As silentweed suggested, this tut will help.
    http://www.senocular.com/flash/tutorials/preloading/

    In case that's confusing, here's the breakdown.
    -In your linkage, you should only have an identifier name and should only have 'Export for ActionScript' checked.
    If 'Export in first frame' is checked, all linkage symbols are added to the first frame of the .swf during export. This means you can't see anything until that first frame is loaded, including your preloader, or more specifically, the frame your preloader is on.
    You get around this by un-checking 'export in first frame'.

    The catch is that they have to be exported on some frame in order to be available for attachMovie calls later on. Basically, flash can only preload whats on the timeline, not whats in the library. The trick is to pick a key frame between your preloader and start of content and drag out one instance of each symbol with linkage to that key frame. Now if you just set your preloader to skip the linkage frame when done, no one will know its there but you'll get a perfectly accurate preloader.

    I usually start content on frame 5. I put my preloader on frame 1 and store all linkage content on frame 3. When my preloader is done, I tell the main timeline to gotoAndStop(5); so that frame 3 never gets displayed.
    Last edited by jAQUAN; 02-24-2007 at 05:12 PM.

  5. #5
    Senior Member
    Join Date
    Aug 2001
    Location
    New York City
    Posts
    409
    nice...thanks ! yea, I was trying for another way around putting the linkaged MC's on a frame...but it does make a lot of sense . Thanks for following up and checking the other thread!

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