A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Set drag limits from code?

  1. #1
    Senior Member lopez1_de's Avatar
    Join Date
    Oct 2001
    Location
    Germany
    Posts
    299

    resolved [RESOLVED] Set drag limits from code?

    Hi,

    is there any way to set the drag limits from code? I can't figure it out. Need to dynamically set the limits.

    Thank you in advance. Have a nice day!
    visit my homepage -> ejected.de

  2. #2
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    When looking in flash9 export code drag & drop are made like this:

    public function onMouseDown (_e:MouseEvent):void
    {
    this.startDrag (false,new Rectangle (100,110,300,190));
    }
    public function onMouseUp (_e:MouseEvent):void
    {
    this.stopDrag();
    }

    so if you handle mouse drag&drop by yourself you can add you own draglimits.
    Simple way could be that you add a rectangle variable to your object and use it in "startDrag" function... I could try to make an example later tonight..

  3. #3
    Senior Member lopez1_de's Avatar
    Join Date
    Oct 2001
    Location
    Germany
    Posts
    299
    Thanks! Sounds great. How do you look into the exported code?
    visit my homepage -> ejected.de

  4. #4
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    If you use flash9 export mode then there is white "newspaper like" icon next to green "play movie" icon. I'm not sure if that is real exported code but it should be close enough actionscript3 what it shows..

  5. #5
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Here is tested code,.. little bit change in event code but I'n not sure which way is the proper way... wont work in 3dfa, just flash9 export:

    Execute script below as starting script...
    Just add "star" object and then modify / create new Rectangle for myLimits variable in runtime.

    Code:
    var star = element ("Paint 3");
    var myLimits = new Rectangle(0,0,300,300);
    
    star.addEventListener(MouseEvent.MOUSE_DOWN, drag);
    star.addEventListener(MouseEvent.MOUSE_UP, drop);
    
    function drag(event:Event):void
    {
    star.startDrag(false, myLimits);
    }
    
    function drop(event:Event):void
    {
    star.stopDrag();
    }
    There is a better or more dynamic way to do this but anyway.. found above code from flashkit forums

  6. #6
    Senior Member lopez1_de's Avatar
    Join Date
    Oct 2001
    Location
    Germany
    Posts
    299
    Thank you! Works great.
    visit my homepage -> ejected.de

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