Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a way to emulate the selection tool?

Status
Not open for further replies.

iostream71

Programmer
Mar 13, 2002
229
US
i was wondering how i could duplicate the selection tool in flash. i want to click a tool button, then drag a square shape on my 'stage'. anybody done this before?
 
create your tool button

then on release, attachmovie , which is your square with a drag option set to true.
 
I don't know about actually doing proper 'selection' (although doing a hit test between the outline you draw and any other objects on stage would be a partial solution) but this code will do the outline drawing for you:

//set up event handlers
this.onMouseDown = startBox;
this.onMouseUp = endBox;

function startBox() {
//set box start point at mouse location
var startX = _xmouse;
var startY = _ymouse;
//create selection box (attach from library)
this.attachMovie('selectionBox', 'box', 100, {_x:startX, _y:startY});
this.onEnterFrame = function() {
//do dragging effect
box._xscale = _xmouse-startX;
box._yscale = _ymouse-startY;
};
}

function endBox() {
//'freeze' selection outline
this.onEnterFrame = null;
}

You'll need to have a movieclip in the library with its linkage property set to 'selectionBox' which must be a square sized 100 pixels to a side so that the code will scale the outline properly.

Alternatively you could use virtually the same code to draw lines using the new drawing functions in MX.
 
i had come up with a solution similar to yours. one problem i have, is that it scales out from the center. i was trying to make it scale downward, just like the selection tool

basically, what i'm trying to do is:
click the tool
drag a square shape on the stage
display info in the shape while it's being drawn
 
What if, inside the movie clip, you align the top left to the registration point instead of the center?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top