all groups > flash actionscript > september 2007 >
You're in the

flash actionscript

group:

imput field that creates my draggable area bondries



imput field that creates my draggable area bondries splotter
9/21/2007 5:39:51 PM
flash actionscript: Hi all,
Im working on a project that allows users to drag shapes on to the screen - I
need a heads up on what to look for;
I want to have my user in a page enter the x and y of the draggable area then
next to the page that contains the objects.

any ideas here?
Re: imput field that creates my draggable area bondries splotter
9/21/2007 5:45:51 PM
If I have a public var that defines the draggable boundries as dragBnd

so the code currently reads as follows

public var dragBnd:Rectangle = new Rectangle (130,75,350,200);

now if I had a file that writes out a value for 130,75,350,200 that would
probably work. my question is do I create a new as file that has 4 text fields
that writh to this as file, how the heck do I do this?
Re: imput field that creates my draggable area bondries SymTsb
9/21/2007 6:16:56 PM
well, add four text fields to your movie. add four vars to the as that will
record/store these values for you. add a button clip that you can have the
user press after they've entered the bounds name this button setBnds

setBnds.addEventListeners( MouseEvent.CLICK, setBounds );

function setBounds( e:MouseEvent ):void {
dragBnd.topLeft = Number(topLeft.text);
dragBnd.topRight = Number(topRight.text);
dragBnd.bottomLeft = Number(bottomLeft.text);
dragBnd.bottomRight = Number(bottomRight.text);
}

make sure that you test equality of the text fields so that none of them have
a null value. You may want to set a group of defaults i.e. 20, 20, 20, 20 from
your other post and if there isn't anything entered into the field, use the
default value instead. This is the general jist of how it is done though.
Re: imput field that creates my draggable area bondries splotter
9/21/2007 6:20:28 PM
Re: imput field that creates my draggable area bondries SymTsb
9/21/2007 6:23:24 PM
put it all in the container. there is absolutely no need for two extra as
files. this can all be done inside the container that you are trying to
control object in. This is where you defined your bounds with the Rectangle
object and you'll still need to do that as a start. Then you can have the
setBnds button change them after the user has input data.
Re: imput field that creates my draggable area bondries splotter
9/21/2007 6:51:20 PM
What the heck is the problem here?

package
{

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.geom.Rectangle;
import dragBnd;

public class DragDrop extends MovieClip
{
public var __targetPiece;
public var _origX:Number;
public var _origY:Number;
public var dragBnd:Rectangle = new Rectangle(130,75,350,200);

public function dragBnd()
{
setBnds.addEventListeners( MouseEvent.CLICK, setBounds );

function setBounds( e:MouseEvent ):void {
dragBnd.topLeft = Number(topLeft.text);
dragBnd.topRight = Number(topRight.text);
dragBnd.bottomLeft = Number(bottomLeft.text);
dragBnd.bottomRight = Number(bottomRight.text);
}


public function DragDrop()

{
_origX = this.x
_origY = this.y;
this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
this.addEventListener(MouseEvent.MOUSE_UP, dropMovie);
this.buttonMode = true;
setBnds.addEventListeners( MouseEvent.CLICK, setBounds );
}


private function dragMovie(event:MouseEvent):void
{
this.startDrag(true,dragBnd);
}


private function dropMovie(event:MouseEvent):void
{
this.stopDrag();
}
}
}
Re: imput field that creates my draggable area bondries SymTsb
9/21/2007 7:06:02 PM
Well, a few things... I'm going to work on a valid sample of the code later
today. I'll try to get back with you on it later.



package
{

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.geom.Rectangle;

// What is the purpose of this???
import dragBnd;

public class DragDrop extends MovieClip
{
public var __targetPiece;
public var _origX:Number;
public var _origY:Number;
public var dragBnd:Rectangle = new Rectangle(130,75,350,200);

public function dragBnd()
{
// This only works if you have a button named setBnds declared first....
// Even if it is on the timeline, putting it in this class isn't going to do
anything for you.
// var setBnds:MovieClip = MovieClip(root).setBnds;
setBnds.addEventListeners( MouseEvent.CLICK, setBounds );
}

function setBounds( e:MouseEvent ):void {

// This function like dragBnd() will only work with a little bit of targetting
done first.
dragBnd.topLeft = Number(topLeft.text);
dragBnd.topRight = Number(topRight.text);
dragBnd.bottomLeft = Number(bottomLeft.text);
dragBnd.bottomRight = Number(bottomRight.text);
}


public function DragDrop()

{
_origX = this.x
_origY = this.y;
this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
this.addEventListener(MouseEvent.MOUSE_UP, dropMovie);
this.buttonMode = true;
dragBnd();
}


private function dragMovie(event:MouseEvent):void
{
this.startDrag(true,dragBnd);
}


private function dropMovie(event:MouseEvent):void
{
this.stopDrag();
}
}
}
Re: imput field that creates my draggable area bondries splotter
9/21/2007 8:14:44 PM
Re: imput field that creates my draggable area bondries splotter
9/21/2007 9:00:24 PM
// This only works if you have a button named setBnds declared first....
// Even if it is on the timeline, putting it in this class isn't going to do
anything for you.
// var setBnds:MovieClip = MovieClip(root).setBnds;
setBnds.addEventListeners( MouseEvent.CLICK, setBounds );
}

Do you mean that even if I have this a a button instance of setBnds I need to
declare this a s a var on my dimline?
Re: imput field that creates my draggable area bondries SymTsb
9/21/2007 9:46:13 PM
Re: imput field that creates my draggable area bondries splotter
9/21/2007 10:08:10 PM
Re: imput field that creates my draggable area bondries SymTsb
9/21/2007 10:11:24 PM
Re: imput field that creates my draggable area bondries splotter
9/21/2007 10:17:56 PM
I think I just need to take a break for a second...I feel like I should be zigging when I should have been zagging,

Re: imput field that creates my draggable area bondries SymTsb
9/22/2007 12:00:00 AM
I added a new post to my site pertaining to your questions. You can download
the source FLA (requires Flash CS3) and read the post to hopefully better
understand how I achieved the result.

http://sd-dezign.com/blog/?p=42
AddThis Social Bookmark Button