A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Generic drag code

  1. #1
    Spinal Tap's Road Manager
    Join Date
    Sep 2006
    Location
    Purgatory
    Posts
    86

    Generic drag code

    hey all,

    i've got this code here, that allows the user of my movie to drag an object, here is the code for rectangle01 and rectangle02


    rectangle01.onPress = function() {
    this.startDrag(false);
    updateAfterEvent();
    };
    rectangle01.onRelease = function() {
    this.stopDrag();
    };


    rectangle02.onPress = function() {
    this.startDrag(false);
    updateAfterEvent();
    };
    rectangle02.onRelease = function() {
    this.stopDrag();
    };



    the thing is... i plan on having around 100 objects... and i really don't want to write individual drag code for each one...

    is there a code that, instead of, for example "rectangle02.onPress = function()", starts with something like "CURRENTOBJECT.onPress = function()" so it will drag the current selected object?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    for (var i = 0; i <= 100; i++)
    {
    this["rectangle"+i].onPress = function ()
    {
    this.startDrag (false);
    updateAfterEvent ();
    };
    this["rectangle"+i].onRelease = function ()
    {
    this.stopDrag ();
    };
    }


    eliminate 0 from 01.
    - The right of the People to create Flash movies shall not be infringed. -

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