To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-15-2004, 02:22 PM   #1
Arrowgraphics
Member
 
Join Date: Sep 2004
Posts: 35
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
__________________
It's In The Mail
Arrowgraphics is offline   Reply With Quote
Old 10-15-2004, 04:06 PM   #2
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
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();
}

__________________
jbum is offline   Reply With Quote
Old 10-15-2004, 04:22 PM   #3
Arrowgraphics
Member
 
Join Date: Sep 2004
Posts: 35
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.
__________________
It's In The Mail
Arrowgraphics is offline   Reply With Quote
Old 10-15-2004, 04:24 PM   #4
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
code:

function setupdrag()
{
dragger.onPress = function()
{
this._parent.startDrag();
}
dragger.onRelease = function()
{
this._parent.stopDrag();
}
}

__________________
jbum is offline   Reply With Quote
Old 10-15-2004, 04:53 PM   #5
Arrowgraphics
Member
 
Join Date: Sep 2004
Posts: 35
That does it

Thanks
__________________
It's In The Mail
Arrowgraphics is offline   Reply With Quote
Old 10-15-2004, 06:06 PM   #6
Arrowgraphics
Member
 
Join Date: Sep 2004
Posts: 35
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
__________________
It's In The Mail
Arrowgraphics is offline   Reply With Quote
Old 10-15-2004, 06:12 PM   #7
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
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
__________________
jbum is offline   Reply With Quote
Old 10-15-2004, 06:31 PM   #8
Arrowgraphics
Member
 
Join Date: Sep 2004
Posts: 35
Yes, that will work, thanks.

I thought they had done away with eval in 2.0
__________________
It's In The Mail
Arrowgraphics is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 -4. The time now is 12:58 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.