Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 05-20-2011, 10:49 PM   #1
Myth of Echelon
Member
 
Join Date: Apr 2011
Posts: 69
Default startDrag Confined to Y Axis

After adapting loads of code from load of different places, I've ending up with this code.

ActionScript Code:
import flash.events.MouseEvent; var constraints:Rectangle = new Rectangle(text123.width/2, stage.stageHeight/2, 0 ,text123.width - text123.height); text123.addEventListener(MouseEvent.MOUSE_DOWN, moveText); stage.addEventListener(MouseEvent.MOUSE_UP, freezeText); stage.addEventListener(MouseEvent.MOUSE_OUT, freezeText); function moveText (evt:MouseEvent):void{     text123.startDrag(false, constraints); } function freezeText (evt:MouseEvent):void{     text123.stopDrag(); }

I cannot get this movieclip to only drag vertically, and not be contained by the stage. I'm trying to create a masked, non-scrollbar, scrollable text.

Last edited by Myth of Echelon; 05-20-2011 at 10:50 PM. Reason: Unnecessary information contained
Myth of Echelon is offline  
Old 05-21-2011, 10:04 PM   #2
chunobi
Member
 
Join Date: May 2011
Posts: 98
Default

So what exactly happens now when you drag? Do you want text123 to be dragged only vertically and over the whole length of the stage or? I can't seem to understand what you're trying to do..
chunobi is offline  
Old 05-21-2011, 10:13 PM   #3
GordonG
Senior Member
 
Join Date: Feb 2008
Posts: 326
Default

I just copied your code into a new flash file, CS4. I created a movieClip on the stage: text123 with one text field inside of it. It works perfectly without modification. So there is nothng wrong with your code, per se. The problem is elswhere: Make sure you have a movieClip instance on the stage with that instance name. Becareful of what is inside movieClip text123.
GordonG is offline  
Old 05-21-2011, 10:41 PM   #4
Myth of Echelon
Member
 
Join Date: Apr 2011
Posts: 69
Default

Hmm. Let me elaborate for you.

I have a movieclip called "text123". Within it I simply have a alpha-rectangle and 3 static text fields. When the .swf is compiled, it's fine. As soon as I click on the movieclip it shifts to the right exactly half it's width. And it let's me drag it up more than down before halting and resulting to move..

It's frustrating me so much D;
Myth of Echelon is offline  
Old 05-21-2011, 10:47 PM   #5
chunobi
Member
 
Join Date: May 2011
Posts: 98
Default

ActionScript Code:
var constraints:Rectangle = new Rectangle(text123.width/2, stage.stageHeight/2, 0 ,text123.width - text123.height); //Shift right half its width is caused by first parameter. Change it to text123.x if you want it to stay at its spot. //The second parameter defines how high your text123 can be dragged; e.g. to half the stage. //The fourth parameter decides how far away you can drag it vertically from the second parameter.
chunobi is offline  
Old 05-21-2011, 10:54 PM   #6
Myth of Echelon
Member
 
Join Date: Apr 2011
Posts: 69
Default

Okay, I've changed it to

var constraints:Rectangle = new Rectangle(text123.X, text123.x, 0 , 900000000);

It solves the half movement thing and I can now drag up unlimitedly, but not down? :S
I would be able to work it out if I ever had the parameters explains to me, but I'm working on bits and pieces I've picked up from random websites :/
Myth of Echelon is offline  
Old 05-21-2011, 11:02 PM   #7
GordonG
Senior Member
 
Join Date: Feb 2008
Posts: 326
Default

wait. you were a little unclear in your initial problem statement.

Answer this question explicitly:

1. after it settles to it's position when you click on it, does it move left and right at all?

Yes, it does move left and right. No it doesn't

2. I see a problem that is intentional:

you assign mouse out to the stop drag code. That means if you dag off the moveClip it will stop moving and the drag is over. That is what you intend, yes or no?

This no bug at all, but behavior that has been attached. If you want to keep dragging no matter where you move the mouse, keep dragging until you let go of the mouse, then the delete the mouse out event listener attach.

fix that and you'll get the behavior, apparently, you expect.

Last edited by GordonG; 05-21-2011 at 11:04 PM.
GordonG is offline  
Old 05-21-2011, 11:02 PM   #8
chunobi
Member
 
Join Date: May 2011
Posts: 98
Default

Whenever you need to know something about a build-in class you can simply google 'as3 class'; in this case 'as3 Rectangle'. Most of the time the first hit will be Adobe's documentation. This is what it says:

Rectangle(x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0)
Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters.

So basically you are creating a new rectangle (duh), which theoretically has 0 width (let's pretend it's a line) at position text123.x, text123.y and with 900000000 height). The second parameter of startDrag() then tells that your text123 should stay in this 'rectangle' at all times.

So the reason why it's only unlimited draggable to one side is your second parameter, which you could replace with -900000000 for example)
chunobi is offline  
Old 05-22-2011, 12:20 PM   #9
Myth of Echelon
Member
 
Join Date: Apr 2011
Posts: 69
Default

Quote:
Whenever you need to know something about a build-in class you can simply google 'as3 class'; in this case 'as3 Rectangle'. Most of the time the first hit will be Adobe's documentation. This is what it says:

Rectangle(x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0)
Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters.

So basically you are creating a new rectangle (duh), which theoretically has 0 width (let's pretend it's a line) at position text123.x, text123.y and with 900000000 height). The second parameter of startDrag() then tells that your text123 should stay in this 'rectangle' at all times.

So the reason why it's only unlimited draggable to one side is your second parameter, which you could replace with -900000000 for example)
Thanks for the tip.

Ohhh so the "constaints" is the rectangle that it can only move across. I see. I'll try something now and get back to you. Thanks for the help
------------------------------------------------------------------------

Quote:
wait. you were a little unclear in your initial problem statement.

Answer this question explicitly:

1. after it settles to it's position when you click on it, does it move left and right at all?

Yes, it does move left and right. No it doesn't

2. I see a problem that is intentional:

you assign mouse out to the stop drag code. That means if you dag off the moveClip it will stop moving and the drag is over. That is what you intend, yes or no?

This no bug at all, but behavior that has been attached. If you want to keep dragging no matter where you move the mouse, keep dragging until you let go of the mouse, then the delete the mouse out event listener attach.

fix that and you'll get the behavior, apparently, you expect.
No, it moves up and down.

And I know the function of MOUSE_OUT, that was intentional. But the way I am interacting with it is by clicking down, dagging up, releasing mouse, moving mouse down and repeating.
Myth of Echelon is offline  
Old 05-22-2011, 12:30 PM   #10
Myth of Echelon
Member
 
Join Date: Apr 2011
Posts: 69
Default

Okay I have now changed it to:
ActionScript Code:
import flash.events.MouseEvent; text123.buttonMode = true; var constraints:Rectangle = new Rectangle(text123.x, text123.y, 0 , -900000000 - 900000000); text123.addEventListener(MouseEvent.MOUSE_DOWN, moveText); stage.addEventListener(MouseEvent.MOUSE_UP, freezeText); function moveText (evt:MouseEvent):void{     text123.startDrag(false, constraints); } function freezeText (evt:MouseEvent):void{     text123.stopDrag(); } /*1st parameter: 'text123.x' so the rectangle's x coordinate starts at the center of text123 2nd parameter: 'text123.y' so the rectangle's y coordinate starts at the center of text123 3rd parameter: '0' so that the rectangle has a width of 0, to make it a line 4th parameter: '-900000000 - 900000000' so that text123 has near unlimited space to move up and down*/

it is now only moving up and down. it will move up unlimitedly, but not down.

Nearly there >.<
Myth of Echelon is offline  
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:37 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.