A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Drag and Drop Help!

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    12

    Drag and Drop Help!

    i'm developing an drag and drop alphabet game in flash cs5(AS3). the goal is to select 1 among the 3 given objects that start w/ the given alphabet and drag it onto the box beside the alphabet. i use external A.S. file. just like this tutorial:
    http://www.youtube.com/watch?v=ALqGYMsRWxw
    i created 26 objects/mcs divided by 3 choices per alphabet. I named it :
    False_duck, True_apple, False_clock. per scene
    My problem is:
    *How can i make mcs with 'True' as correct and all mcs with 'False' as incorrect answer when dragged into the box(target).

    any suggestions and reply would greatly appreciated! thanks!
    Attached Images Attached Images

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    This should help you get started.

    Actionscript Code:
    function TrueOrFalse()
    {
        if (ButtonName.indexOf("True") != -1)
        {
            trace("This is a true answer");
        }
        else
        {
            trace("This is a false answer");
        }
    }
    True_Apple.onPress = function()
    {
        ButtonName = this._name;
        this.startDrag();
        trace(ButtonName);
        TrueOrFalse();
    };
    True_Apple.onRelease = function()
    {
        ButtonName = "";
        stopDrag();
    };
    False_Apple.onPress = function()
    {
        ButtonName = this._name;
        this.startDrag();
        trace(ButtonName);
        TrueOrFalse();
    };
    False_Apple.onRelease = function()
    {
        ButtonName = "";
        stopDrag();
    };

    you just need to incorporate your hitTest within the function, probably.

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Just incase you can not quite manage to make the hitTest, here we go.

    Actionscript Code:
    function TrueOrFalse()
    {
        if (ButtonName.indexOf("True") != -1)
        {
            trace("This is a true answer");
        }
        else
        {
            trace("This is a false answer");
        }
    }
    True_Apple.onPress = function()
    {
        ButtonName = this._name;
        this.swapDepths(_root.getNextHighestDepth());
        this.startDrag();
        trace(ButtonName);
    };
    True_Apple.onRelease = function()
    {
        stopDrag();
        if (this.hitTest(HitObject))
        {
            TrueOrFalse();
        }
    };
    False_Apple.onPress = function()
    {
        ButtonName = this._name;
        this.swapDepths(_root.getNextHighestDepth());
        this.startDrag();
        trace(ButtonName);
    };
    False_Apple.onRelease = function()
    {
        stopDrag();
        if (this.hitTest(HitObject))
        {
            TrueOrFalse();
        }
    };

  4. #4
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    thanks a lot! but the hittest code still didn't work. this is my code for the main AS file.
    in this ff. code i changed the instance name of 3 mcs as True1, False1,False2.
    __________________________________________________ ________________________
    package data.scripts {

    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import flash.display.Stage
    import flash.display.DisplayObject;



    public class DragDropTarget extends MovieClip
    {

    protected var OP:Point
    public function DragDropTarget()
    {
    // constructor code
    OP = new Point (x,y);
    buttonMode = true;
    addEventListener(MouseEvent.MOUSE_DOWN, down);
    }

    protected function down( event:MouseEvent ):void
    {

    parent.addChild( this);
    startDrag();
    stage.addEventListener(MouseEvent.MOUSE_UP, stageUp);
    }
    protected function stageUp(event:MouseEvent):void

    {
    stage.removeEventListener(MouseEvent.MOUSE_UP,stag eUp);
    stopDrag();
    if(dropTarget)
    {
    if(dropTarget.parent.name == "frame")
    {
    scaleX = scaleY = 1;
    y = stage.stageHeight - height - 230;
    x = stage.stageHeight - width + 220;
    buttonMode = false;
    removeEventListener(MouseEvent.MOUSE_DOWN,down);
    for(var i:Number=1; i<30; i++);
    var Mc:String = "True" + i;
    if (Mc == Mc)

    {
    trace("yes");
    // Greetings_txt.text ="You are Correct!";
    // Correct_txt.text ="Apple";

    }
    else
    {
    trace("no");
    }

    }


    else
    {
    returnToOP();
    }
    }
    else
    {
    trace("drop sumthing");
    }
    }
    protected function returnToOP():void
    {
    x=OP.x;
    y=OP.y;
    }
    }
    }
    __________________________________________________ ________________________
    On the bold text. its not working but i want it to read and identify the "True" + the number followed in an instance name.
    i have 26 Mcs with "True"+Numbers Ins Name. thats why i want to have a main AS file which can generate all 26 A.S. file through Class.

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Sorry, i did not notice the AS3 tucked away, it works fine and dandy in AS2, I simply don't have the time to evolve my AS3.

    Cheers

  6. #6
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hi,

    I just can't seem to figure out what you're trying to do in that bold text, are you comparing a String to itself??? That'll always return true...

    Can you possibly post your FLA file here?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  7. #7
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    I have 26 MCs and using only one target. 26 True and 26 false. (note that on the picture above i divided 26 MCs by 3 MCs as choices per scene.) if i named all 26 true MCs(correct answer) with True1, True2, etc... and 26 false MCs w/ False1, False2 etc...
    and drag it to only one target, the target then identify which MCs has "True" and "False"
    at the beginning of their Ins. Name. and trace it IF its correct answer or not.

  8. #8
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    my only problem is on the bold text as i didnt make the target identify all the false MCs and the True MCs based on their INstance name. I didnt know how to use currentTarget as well. the code is from an external AS3 file that is the source code of the 26 MCs. they are linked by a class.
    Can you give me some idea?

  9. #9
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    Im sorry..im stuck with that string to itself. i dont know what is the right code for that...
    do you have any idea???..

  10. #10
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Quote Originally Posted by Nig 13 View Post
    Can you possibly post your FLA file here?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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