1

I am trying to write android application in flash CS6 and I'm using sprite.

When I ran the application I draw in the first screen.

When I move to the next screen the line that I've drawn in the first screen still remain in the next screen.

My code:

import flash.display.Sprite;
import flash.events.MouseEvent;

var ranWidth:Number;
var myLine:Sprite = new Sprite();
addChild(myLine);

function onMouseDown(event:MouseEvent):void
{
 stage.addChild(myLine);
 ranWidth = Math.round((Math.random() * 10)+2);
 myLine.graphics.lineStyle(ranWidth, 0xff0000, 100);
 stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
 stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);    
}
function onMouseMove(event:MouseEvent):void
{
 myLine.graphics.lineTo(mouseX, mouseY);
}
function onMouseUp(event:MouseEvent):void
{
 stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
 stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}

Can anyone help me how to solve this problem?

How to remove the line that I've drawn in the first screen so that it wont remain when I move to the next screen.

miken32
  • 42,008
  • 16
  • 111
  • 154
adda92
  • 11
  • 1
  • What do you mean with "screen"? Do you mean the next frame of the timeline in Flash CS6? – null Jun 05 '15 at 10:41
  • Don't add anything to the stage. Create your own display list from your document class or timeline. – BotMaster Jun 05 '15 at 12:14

1 Answers1

0

First of all, there's no reason to add your line over and over again. This line is not doing much, remove it:

stage.addChild(myLine);

You already add the Sprite with this line:

addChild(myLine);

Whatever you mean by "screen", DispalyObjects that you add with code to the display will stay there until you remove them. If you add it yourself, you should remove it if you don't need it anymore.

To do this, use this code when you change the screen:

removeChild(myLine);

This code will only work if you delete the line stage.addChild(myLine);

null
  • 5,207
  • 1
  • 19
  • 35