0

i created an mc with instancename subtraktiv that plays automaticly until frame 31. in frame 31 i have the actionscript for drag and drop for a mc named cyan2

here is the code in the timeline of mc subtraktiv :

this.stop();

cyan2.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_8);

function fl_ClickToDrag_8(event:MouseEvent):void
{
cyan2.startDrag();
}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_8);

function fl_ReleaseToDrop_8(event:MouseEvent):void
{
cyan2.stopDrag();
}

in the main scene is a button to replay the mc subtraktiv

here is the code:

button_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
subtraktiv.play();
}

the problem - when i klick on the button - it works - the mc subtraktiv plays again. but when i drag and drop the mc cyan2 and afterwards i click on the button to replay the mc subtraktiv - it does replay the mc subtraktiv but the moved element befor does not play anymore - it remains on the draged position.

why?

i say - play it again from frame number 1 where the element has its fixed place - why does it ignore it?

what am i doing wrong?

thanks for help !

  • Because mixing timelines and scripting (other then simple commands like **play** / **stop** / **gotoAndWhatever**) results in these kind of troubles. To avoid it you need not just replay your **subtractiv**, you need to remove the instance of that **subtractiv** tainted by your actions and replace it with the fresh copy. For example, give **subtractiv** a class and replace the used **subtractiv** with the **new** instance of its class. – Organis Jul 24 '20 at 15:27
  • can you give me an advice, how i have to do this? i tried it on behalf of a tutorial, but it does not work at all... – froschloeffel Jul 28 '20 at 15:44
  • You can do it in a timeline manner. Frame 1: **subtractiv** as a child and **stop();** as a script. Frame 2: empty. Once you need to refresh things, you just need to **play();** this timeline, it will go through Frame 2 disposing of anything that was there, then it goes to Frame 1 again where fresh instance of **subtractiv** is created. – Organis Jul 28 '20 at 16:44
  • i tried it in all ways but it does not load the instance new. the drag and drop is obviously stronger than anything else. – froschloeffel Jul 29 '20 at 11:57

1 Answers1

0

the only object, that is placed ist the button. all the others come by script

here is my code on the main timeline

var neueInstanzSubtraktiv:Subtraktiv = new Subtraktiv();
addChild(neueInstanzSubtraktiv);

button1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void

{

trace("Mausklick erfolgt");

neueInstanzSubtraktiv.gotoAndPlay(1);

}

neueInstanzSubtraktiv.gelb1.addEventListener(MouseEvent.MOUSE_DOWN,fl_ClickToDrag);

function fl_ClickToDrag(event:MouseEvent):void

{

neueInstanzSubtraktiv.gelb1.startDrag();

}

this.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

function fl_ReleaseToDrop(event:MouseEvent):void
{


neueInstanzSubtraktiv.gelb1.stopDrag();
}

neueInstanzSubtraktiv.cyan2.addEventListener(MouseEvent.MOUSE_DOWN,fl_ClickToDrag_2);

function fl_ClickToDrag_2(event:MouseEvent):void

{
    neueInstanzSubtraktiv.cyan2.startDrag();
}

this.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_2);

function fl_ReleaseToDrop_2(event:MouseEvent):void
{
    neueInstanzSubtraktiv.cyan2.stopDrag();
}

neueInstanzSubtraktiv.rot1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_3);

function fl_ClickToDrag_3(event:MouseEvent):void
{
    neueInstanzSubtraktiv.rot1.startDrag();
}

this.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_3);

function fl_ReleaseToDrop_3(event:MouseEvent):void
{
    neueInstanzSubtraktiv.rot1.stopDrag();
}

on the timeline of the instance subtraktiv is on frame 31 the code

this.stop();

if there would be a possibility to upload the fla i would do so. this way you could see the whole file.

it works but after the drag and drop it does not propper anymore thank you for help