A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS3 Drag and Drop multiple objects - improving code suggestion

  1. #1
    Flash Genie letschillout's Avatar
    Join Date
    Feb 2007
    Location
    31.52949, 74.347272
    Posts
    146

    Post AS3 Drag and Drop multiple objects - improving code suggestion

    Hi, i want to improve my code for drag drop
    seven different or multiple objects to be moved in any three of target places
    then target value will be search by category or feature wise,

    any suggestion will be welcome in helping writing the code.
    this drag n drop code work but i want to improve it, pls guide thks

    //--------------------------------
    //---------------Romantic--------------
    //--------------------------------
    romantic.addEventListener(MouseEvent.MOUSE_DOWN, romantic_pick);
    romantic.addEventListener(MouseEvent.MOUSE_UP, romantic_drop);
    romantic.buttonMode = true;
    //---functions
    //--------------------------------
    //--------------------------------
    function romantic_pick(event:MouseEvent):void {
    romantic.startDrag(true);
    if(romantic.x > 894 && romantic.x < 989 && romantic.y > 97 && romantic.y < 229)
    {
    msg.text = "";
    }}
    //--------------------------------
    //--------------------------------
    //--------------------------------
    function romantic_drop(event:MouseEvent):void {
    romantic.stopDrag();
    boxone_romantic();

    }
    //------------------------------------
    //--------------------------------
    //--------------------------------
    //--------------------------------
    function smallsize_romantic()
    {
    romantic.width = 50;
    romantic.height = 75;
    }
    //--------------------------------
    //--------------------------------
    //--------------------------------

    function boxposition1_romantic()
    { romantic.x =540;
    romantic.y =225;
    msg1.text = "Romantic";
    option= 1;
    romantic.rotation=-9.3;
    romantic.removeEventListener(MouseEvent.MOUSE_DOWN , romantic_pick);
    romantic.removeEventListener(MouseEvent.MOUSE_UP, romantic_drop);
    romantic.buttonMode = false;
    }
    //--------------------------------
    //--------------------------------
    //--------------------------------
    function boxposition2_romantic()
    { romantic.x =550;
    romantic.y =300;
    msg2.text = "Romantic";
    option=2;
    romantic.rotation=-9.3;
    romantic.removeEventListener(MouseEvent.MOUSE_DOWN , romantic_pick);
    romantic.removeEventListener(MouseEvent.MOUSE_UP, romantic_drop);
    romantic.buttonMode = false;

    }
    //--------------------------------
    //--------------------------------
    //--------------------------------
    function boxposition3_romantic()
    { romantic.x =560;
    romantic.y =365;
    msg3.text = "Romantic";
    option=3;
    romantic.rotation=-9.3;
    romantic.removeEventListener(MouseEvent.MOUSE_DOWN , romantic_pick);
    romantic.removeEventListener(MouseEvent.MOUSE_UP, romantic_drop);
    romantic.buttonMode = false;

    }
    //--------------------------------
    //---------------------
    Charag - 3D, Flash Games, Animations,
    Website Development & More...


  2. #2
    Flash Genie letschillout's Avatar
    Join Date
    Feb 2007
    Location
    31.52949, 74.347272
    Posts
    146
    after going through many googling... i recode as below
    but giving error, though code working fine
    ----------------------
    "TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at myweekend_test04_fla::MainTimeline/step2()"
    --------------------------

    stop();
    var stamps:Array = ["spa", "romantic", "beach"];
    var startpoint:Point = new Point();
    //------------------------------------
    //--------------function--------------
    function pickUp(event:MouseEvent):void {
    event.target.startDrag(true);
    event.target.rotation=0;
    startpoint.x = event.target.x;
    startpoint.y = event.target.y;

    //x,y starting point
    position1.text = event.target.name +"\n"+"x:"+startpoint.x +", y:"+startpoint.y;
    }

    function dropIt(event:MouseEvent):void {
    event.target.stopDrag();
    if (event.target.dropTarget != null && event.target.dropTarget.parent == box1){
    msg1.text = event.target.name;
    event.target.rotation=-9.3;
    event.target.scaleX=0.8;
    event.target.scaleY=0.8;
    event.target.removeEventListener(MouseEvent.MOUSE_ DOWN, pickUp);
    event.target.removeEventListener(MouseEvent.MOUSE_ UP, dropIt);
    event.target.buttonMode = false;


    } else {
    if (event.target.dropTarget != null && event.target.dropTarget.parent == box2){
    msg2.text = event.target.name;
    event.target.rotation=-9.3;
    event.target.scaleX=0.8;
    event.target.scaleY=0.8;
    event.target.removeEventListener(MouseEvent.MOUSE_ DOWN, pickUp);
    event.target.removeEventListener(MouseEvent.MOUSE_ UP, dropIt);
    event.target.buttonMode = false;

    } else {
    if (event.target.dropTarget != null && event.target.dropTarget.parent == box3){
    msg3.text = event.target.name;
    event.target.rotation=-9.3;
    event.target.scaleX=0.8;
    event.target.scaleY=0.8;
    event.target.removeEventListener(MouseEvent.MOUSE_ DOWN, pickUp);
    event.target.removeEventListener(MouseEvent.MOUSE_ UP, dropIt);
    event.target.buttonMode = false;
    }

    else{
    event.target.x = startpoint.x;
    event.target.y = startpoint.y;}

    } }
    //x,y starting point
    position2.text = event.target.name +"\n"+"x:"+startpoint.x +", y:"+startpoint.y;
    }

    //------------------------------------
    //------------------------------------
    spa.buttonMode = true;
    romantic.buttonMode = true;
    beach.buttonMode = true;
    //---------------------------
    spa.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    spa.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    //---------------------------
    romantic.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    romantic.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    //-------------------------------------------------
    beach.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    beach.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    //------------------------------------
    //------------------------------------
    btn_press.buttonMode = true;
    btn_press.addEventListener(MouseEvent.CLICK, reset);
    function reset(event:MouseEvent):void {
    gotoAndStop("reset");
    }

    btn_submit.addEventListener(MouseEvent.CLICK, step2);
    function step2(event:MouseEvent):void {

    for (var i=0; i<stamps.length ;i++)
    {
    if(msg1.text == stamps[i] && msg2.text == stamps[i] && msg3.text == stamps[i]){
    gotoAndStop(stamps[i]);
    }
    else{
    if(msg2.text == stamps[i]){
    gotoAndStop(stamps[i]);
    }
    else{
    if(msg3.text == stamps[i]){
    gotoAndStop(stamps[i]);
    }}}}
    }
    Charag - 3D, Flash Games, Animations,
    Website Development & More...


  3. #3

  4. #4
    Senior Member PRadvan's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    261
    Thanks for linking to my AS2 inventory system letschillout.

    I just wanted to share a link to my AS3 version here:
    http://www.freeactionscript.com/2010...entory-system/

    Thanks again!

Tags for this Thread

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