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?
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?
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.
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.
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(); } } }
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(); } } }
// 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?
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,
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
Don't see what you're looking for? Try a search.
|