-
Simple Drag Function within an AS file
I have a movie clip Screen which contains another movie clip dragger. (a drag bar)
I will be attaching instances of this clip as needed.
What I want to do is write a function so that when the dragger bar is pressed in any of the instances of the Screen clip, that instance of Screen can then be dragged.
This function resides in a class Screen which is linked to the movie clip and I am using AS 2.0
This is more or less what I have come up with
Code:
function drag() {
dragger.onPress = startDrag(true);
}
What's throwing me is the paths and use of this in AS 2.0 I know it's simple, sorry this is my first class.
Thanks for your help
-
Senior Member
One way to do it would be to attach the following script to the dragger instance:
code:
on(press)
{
_parent.startDrag();
}
on(release)
{
_parent.stopDrag();
}
-
Hi,
Thanks but I am trying to centralize all the code which is common to the Screen clip. It's got to be something simple, I just can't see it.
-
Senior Member
code:
function setupdrag()
{
dragger.onPress = function()
{
this._parent.startDrag();
}
dragger.onRelease = function()
{
this._parent.stopDrag();
}
}
-
-
I am running into another problem. Can't figure it out.
The function works as long as I include Screen for example: Screen.dragger.onPress Of course In actuality it would be Screen1, Screen2 etc...
So here is the button action, I pass the id to the as file.
Code:
attachMovie("Screen", "Screen1", 2, {id:1});
In my .as file I declare the var
Code:
var capt:String, id:Number;
In the constructor I add the full path
Code:
function Screen() {
path = "Screen" + id + ".dragger";
trace(path);
}
It traces out correctly even when I trace it from within the function but it only works if I hardcode the path.
is this a type mismatch? what is going on?
Thanks
-
Senior Member
First off in when attaching the movie, you need to name the clip using a dynamic id number, like so:
myID = 2;
attachMovie("Screen", "Screen"+myID, 2, {id:myID});
Secondly, your path is a string:
path = "Screen" + id + ".dragger";
You'll need to evalulate it to use it like a movieclip.
path._x += 3; // invalid
mc = eval(path);
mc._x += 3; // valid
-
Yes, that will work, thanks.
I thought they had done away with eval in 2.0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|