A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Simple Drag Function within an AS file

  1. #1
    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

  2. #2
    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();
    }


  3. #3
    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

  4. #4
    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();
    }
    }


  5. #5
    Member
    Join Date
    Sep 2004
    Posts
    35
    That does it

    Thanks
    It's In The Mail

  6. #6
    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

  7. #7
    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

  8. #8
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center