Skip to main content
Participating Frequently
March 15, 2010
Answered

ScrollPane Component

  • March 15, 2010
  • 2 replies
  • 496 views

I need t draw a rectangle on a movie clip(board_mc) by dragging mouse over it......It works fine till here but I want to put the movie clip(board_mc) in scrollpane.

but after doing so the code doesnot work....can u plz guide me how to make this code work after placing the movie clip (board_mc) in scrollpane(say board_scp).

var rectDraw:Shape = new Shape();
var corner:Point;
board_mc.addEventListener(MouseEvent.MOUSE_DOWN, setAnchor);
board_mc.addEventListener(MouseEvent.MOUSE_UP, completeRect);
rectDraw.graphics.lineStyle(0, 0, 0);
rectDraw.graphics.beginFill(0X000000);
rectDraw.graphics.drawRect(0,0,13,45);
function setAnchor(e:MouseEvent):void
{
        corner = new Point(e.stageX, e.stageY);
  rectDraw = new Shape();
  board_mc.addChild(rectDraw);
        board_mc.addEventListener(MouseEvent.MOUSE_MOVE, liveDrag); 
}
function liveDrag(e:MouseEvent):void
{
rectDraw.graphics.clear();
rectDraw.graphics.lineStyle(2, 0X000000); //thickness,color
rectDraw.graphics.drawRoundRect(corner.x, corner.y, e.stageX - corner.x, e.stageY - corner.y,2);
}
function completeRect(e:MouseEvent):void
{
        board_mc.removeEventListener(MouseEvent.MOUSE_MOVE, liveDrag);
        rectDraw.graphics.lineStyle(0, 0, 0);
        rectDraw.graphics.beginFill(0X000000);
  rectDraw.graphics.drawRect(corner.x, corner.y, e.stageX - corner.x, e.stageY - corner.y);
}

This topic has been closed for replies.
Correct answer kglad

apply your listener to the scrollpane's content property. you may need to apply the scrollpane's update() method if there's a size change to the content after drawing.

2 replies

Ned Murphy
Legend
March 15, 2010

Try putting the movieclip in the scrollpane after your existing code...

// first have all your code with board_mc on the stage

sp.source = board_mc;

Participating Frequently
March 15, 2010

what if the user tries to draw rectangle again.....

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 15, 2010

apply your listener to the scrollpane's content property. you may need to apply the scrollpane's update() method if there's a size change to the content after drawing.

kglad
Community Expert
Community Expert
March 15, 2010

how are you adding your movieclip to your scrollpane?


Participating Frequently
March 15, 2010

I am adding movie clip to scrollpane through statement board_scp.source = board_mc;