0
votes

I m currently working on converting one of my as2 game project into as3 (flash pro cs4). But there is a problem on the background movieclip.

I have a function called disposemc:

function disposemc(mcname:MovieClip):void{
    mcname.parent.removeChild(mcname);
    mcname = null
}

Another function called changelayer:

function changelayer(mcname:MovieClip,layer:MovieClip):void{
    layer.addChild(mcname)
}

So in main timeline frame 2 I have a movieclip on stage (placed in IDE) with instance name "bg_mc", then on main timeline frame 3 I have a DIFFERENT mc on stage with the SAME instance name "bg_mc". The purpose of this is to replace the old bg_mc by the new one.

The problem is,

In frame 2, I applied changelayer function to bg_mc and moved it into a child mc of root by addChild, and then applied a function of my CPU image post processing framework and added the bg_mc into an array.

After some stuffs happened, I went nextFrame to frame 3, and found that the new bg_mc didnot replace the old one, instead it overlaps. So I tried disposemc function when leaving frame 2 to get rid of the old bg_mc, and at frame 3 I applied changelayer to bg_mc and added bg_mc to my render array.

And I found that the old bg_mc is off the stage but it is still rendering onto my bitmap data, means it is not nullified like it suppose to be in disposemc function. And it is also hard to access it because the name overlaps. When I call bg_mc in frame 3 it is the new one, but the old one still exists, and from the rendered bitmap data it can see it is still playing. Will making the old mc stop in disposemc function help?

Can anyone give any help? If my structure of making bg is bad, is there any other way to override an instance with a different mc in library?

1
why did you use the same name ? can't you use distinct names and do what you want ? if you want to place a MovieClip a the place of an other you can do clip1.x = clip0.x; clip1.y = clip0.y; clip0.parent.addChild( clip1 ); clip0.parent.removeChild( clip0 );Benjamin BOUFFIER
I m basically saying how to use IDE to replace mc when entering the next frame. your method is what I m doing already, kind of, but it doesn't work.TommyX
ah sorry i don't use flash pro IDE i prefer to know what happening on my code ;)Benjamin BOUFFIER

1 Answers

0
votes

The purpose of this is to replace the old bg_mc by the new one

You work with MovieClip and frames. So use keyframes by design. If you need to place different background in third frame, don't program it, place it. If you want program, don't use MovieClip with keyframes as main navigation instrument.

Main timeline could be easily swapped with very simple logic and several movie clips with only one frame

//Some MovieClips from the library, with only one frame, still designed in Flash IDE
var currentScene:DisplayObject;
var home: MyHove = new MyHove()
var intro:MyIntro = new MyIntro();

navigate(home);
//after some interaction from the user, go to another page        
navigate(intro);

//It will work like gotoAndStop... but better, and give you more control
function navigate(scene: DisplayObject):void{
    if(currentScene != null){
        removeChild(currentScene);
    }

    currentScene = scene;

    if(currentScene != null){
        addChild(currentScene);
        //apply logic for swapping background
    }
}