Tuesday, March 30, 2010

Dynamic movieclip duplication

Hi Everyone,

I am working on dynamic duplication of movieclip when the button is pressed one by one.

In that movieclip there are two buttons ok and cancel.


Here is the piece of code:

var new_panel:please_wait = new please_wait;

click_btn.addEventListener(MouseEvent.MOUSE_DOWN, generate);


function generate(e:MouseEvent):void{
?
?new_panel = new please_wait;
?addChild(new_panel);
?new_panel.addEventListener(MouseEvent.MOUSE_OVER , over_evt);
?new_panel.addEventListener(MouseEvent.MOUSE_DOWN , start_evt);
?new_panel.addEventListener(MouseEvent.MOUSE_UP , stop_evt);
?new_panel.ok_btn.addEventListener(MouseEvent.MOUSE_DOWN , ok_evt);
?new_panel.cancel_btn.addEventListener(MouseEvent.MOUSE_DOWN , cancel_evt);
?
}

function start_evt(e:MouseEvent){
?new_panel.startDrag();
}

function stop_evt(e:MouseEvent){
?new_panel.stopDrag();
?
}

function ok_evt(e:MouseEvent){


}

function cancel_evt(e:MouseEvent){
?removeChild(new_panel);
}

if i create two movieclip, then how i remove a particular movieclip.

i also attached the screen shot for reference..

Anyone Knows reply..

Thanks in advance..

Regards

Saransoft

Dynamic movieclip duplication

I guess the problem with your code is your message box is getting duplicated twice.

You want to remove the previous instance if it is already on the stage.

If I am correct you can use the following code:

var new_panel:please_wait = null;

click_btn.addEventListener(MouseEvent.MOUSE_DOWN, generate);


function generate(e:MouseEvent):void{
?
?if(new_panel.parent)

{

?removeChild(new_panel);

}

?new_panel = new please_wait;
?addChild(new_panel);
?new_panel.addEventListener(MouseEvent.MOUSE_OVER , over_evt);
?new_panel.addEventListener(MouseEvent.MOUSE_DOWN , start_evt);
?new_panel.addEventListener(MouseEvent.MOUSE_UP , stop_evt);
?new_panel.ok_btn.addEventListener(MouseEvent.MOUSE_DOWN , ok_evt);
?new_panel.cancel_btn.addEventListener(MouseEvent.MOUSE_DOWN , cancel_evt);
?
}

function start_evt(e:MouseEvent){
?new_panel.startDrag();
}

function stop_evt(e:MouseEvent){
?new_panel.stopDrag();
?
}

function ok_evt(e:MouseEvent){


}

function cancel_evt(e:MouseEvent){
?removeChild(new_panel);
}

Dynamic movieclip duplication

Hi,

Thanks for your Valuable information.

But i want to know about how can i remove the movieclip when the particular ''cancel button''.

ie: If i create two movieclip then i remove the first movieclip using first cancel button. then second movieclip to second cancel button.

I know you can understand my words.

Thanks in advance..

Regards

Saransoft

You can do that by using the event variable passed to your cancel button event handler.

use folllowing :

Replace following line in your generate function:

newPanel.cancel_btn.addEventListener(MouseEvent.CLICK, cancelWindow);

and copy this function:

function cancelWindow(evnt:MouseEvent)

{

(evnt.currentTarget.parent.parent as MovieClip).removeChild(evnt.currentTarget.parent);

}

You will have to check how many parent you have to use to get to the desired movieclip

Hi,

Thanks for your reply..

regards

Saransoft

  • skin
  • No comments:

    Post a Comment