Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    20
    Member #
    22716
    Hi all,

    Have a drag'n'drop exercise I've built for work, all the code is working fine, just have a little snag I could really use some help on:

    * Basically, I have a bunch of buttons that can be dropped into one of three drop-boxes. Each button is made up of a movie clip, the movie clip is made up of an animation(mc) which in turn has a symbol in it too. All the nesting is fine, all registration points are set properly throughtout all mc's.
    The UP state for each button is a static graphic, the OVER is the actual MC, and the DOWN state is just a static graphic as well.

    * The problem is that the UP, OVER and DOWN states are fine, but the second I start to drag the button it moves down/right, as if the registration is different and reverts to the OVER state, playing the OVER MC again.

    I'll paste the code below for it. My teacher is pretty sure it's a registration issue within one of the MC's, which would make sense, but I've checked them all and they're fine. My gut tells me it's a coding issue, since it occurs once the button is actually dragged (see below to see what I mean).

    Would appreciate any help you guys out there could provide, see how you go with it...

    Cheers in advance,
    O.

    __________________________________________________ _________

    stop();
    import flash.events.*;

    // Initial variable setup
    var dragBtn:SimpleButton = null;
    var originLoc:Point = new Point();
    var currentContainer_1:Number = 0;
    var currentContainer_2:Number = 0;
    var currentContainer_3:Number = 0;

    var feedbackWrong_1:Array = new Array();
    feedbackWrong_1[ 1 ] = wrong_1;
    feedbackWrong_1[ 2 ] = wrong_2;
    feedbackWrong_1[ 3 ] = wrong_3;
    feedbackWrong_1[ 4 ] = wrong_4;
    feedbackWrong_1[ 5 ] = wrong_5;
    feedbackWrong_1[ 6 ] = wrong_6;
    feedbackWrong_1[ 7 ] = wrong_7;

    var correctAnswers_1ictionary = new Dictionary();
    correctAnswers_1[ "make_sounds" ] = "make_sounds";
    correctAnswers_1[ "id_colours" ] = "id_colours";
    correctAnswers_1[ "count_items" ] = "count_items";
    correctAnswers_1[ "animal_sounds" ] = "animal_sounds";
    correctAnswers_1[ "ack_comm" ] = "ack_comm";
    correctAnswers_1[ "expand_words" ] = "expand_words";
    correctAnswers_1[ "read_to_child" ] = "read_to_child";

    var containers_1:Array = new Array();
    containers_1[ 1 ] = container_1;
    containers_1[ 2 ] = container_2;
    containers_1[ 3 ] = container_3;
    containers_1[ 4 ] = container_4;
    containers_1[ 5 ] = container_5;
    containers_1[ 6 ] = container_6;
    containers_1[ 7 ] = container_7;

    var feedbackWrong_2:Array = new Array();
    feedbackWrong_2[ 1 ] = wrong_8;
    feedbackWrong_2[ 2 ] = wrong_9;
    feedbackWrong_2[ 3 ] = wrong_10;
    feedbackWrong_2[ 4 ] = wrong_11;
    feedbackWrong_2[ 5 ] = wrong_12;
    feedbackWrong_2[ 6 ] = wrong_13;
    feedbackWrong_2[ 7 ] = wrong_14;
    feedbackWrong_2[ 8 ] = wrong_15;
    feedbackWrong_2[ 9 ] = wrong_16;

    var correctAnswers_2ictionary = new Dictionary();
    correctAnswers_2[ "expand_sentences" ] = "expand_sentences";
    correctAnswers_2[ "disc_baby_talk" ] = "disc_baby_talk";
    correctAnswers_2[ "make_scrapbook" ] = "make_scrapbook";
    correctAnswers_2[ "play_yesno" ] = "play_yesno";
    correctAnswers_2[ "enc_choice" ] = "enc_choice";
    correctAnswers_2[ "expand_vocab" ] = "expand_vocab";
    correctAnswers_2[ "sing_simp_songs" ] = "sing_simp_songs";
    correctAnswers_2[ "store_fam_items" ] = "store_fam_items";
    correctAnswers_2[ "use_fam_photos" ] = "use_fam_photos";

    var containers_2:Array = new Array();
    containers_2[ 1 ] = container_8;
    containers_2[ 2 ] = container_9;
    containers_2[ 3 ] = container_10;
    containers_2[ 4 ] = container_11;
    containers_2[ 5 ] = container_12;
    containers_2[ 6 ] = container_13;
    containers_2[ 7 ] = container_14;
    containers_2[ 8 ] = container_15;
    containers_2[ 9 ] = container_16;

    var feedbackWrong_3:Array = new Array();
    feedbackWrong_3[ 1 ] = wrong_17;
    feedbackWrong_3[ 2 ] = wrong_18;
    feedbackWrong_3[ 3 ] = wrong_19;
    feedbackWrong_3[ 4 ] = wrong_20;
    feedbackWrong_3[ 5 ] = wrong_21;
    feedbackWrong_3[ 6 ] = wrong_22;
    feedbackWrong_3[ 7 ] = wrong_23;

    var correctAnswers_3ictionary = new Dictionary();
    correctAnswers_3[ "build_vocab" ] = "build_vocab";
    correctAnswers_3[ "build_spatial_rel" ] = "build_spatial_rel";
    correctAnswers_3[ "offer_clues" ] = "offer_clues";
    correctAnswers_3[ "create_categories" ] = "create_categories";
    correctAnswers_3[ "help_follow_steps" ] = "help_follow_steps";
    correctAnswers_3[ "enc_giving_dir" ] = "enc_giving_dir";
    correctAnswers_3[ "use_daily_act" ] = "use_daily_act";

    var containers_3:Array = new Array();
    containers_3[ 1 ] = container_17;
    containers_3[ 2 ] = container_18;
    containers_3[ 3 ] = container_19;
    containers_3[ 4 ] = container_20;
    containers_3[ 5 ] = container_21;
    containers_3[ 6 ] = container_22;
    containers_3[ 7 ] = container_23;

    // Button Start-Drag Event Listeners
    make_sounds.addEventListener(MouseEvent.MOUSE_DOWN , startBtnDrag);
    id_colours.addEventListener(MouseEvent.MOUSE_DOWN, startBtnDrag);
    count_items.addEventListener(MouseEvent.MOUSE_DOWN , startBtnDrag);
    animal_sounds.addEventListener(MouseEvent.MOUSE_DO WN, startBtnDrag);
    ack_comm.addEventListener(MouseEvent.MOUSE_DOWN, startBtnDrag);
    expand_words.addEventListener(MouseEvent.MOUSE_DOW N, startBtnDrag);
    read_to_child.addEventListener(MouseEvent.MOUSE_DO WN, startBtnDrag);
    expand_sentences.addEventListener(MouseEvent.MOUSE _DOWN, startBtnDrag);
    disc_baby_talk.addEventListener(MouseEvent.MOUSE_D OWN, startBtnDrag);
    make_scrapbook.addEventListener(MouseEvent.MOUSE_D OWN, startBtnDrag);
    play_yesno.addEventListener(MouseEvent.MOUSE_DOWN, startBtnDrag);
    enc_choice.addEventListener(MouseEvent.MOUSE_DOWN, startBtnDrag);
    expand_vocab.addEventListener(MouseEvent.MOUSE_DOW N, startBtnDrag);
    sing_simp_songs.addEventListener(MouseEvent.MOUSE_ DOWN, startBtnDrag);
    store_fam_items.addEventListener(MouseEvent.MOUSE_ DOWN, startBtnDrag);
    use_fam_photos.addEventListener(MouseEvent.MOUSE_D OWN, startBtnDrag);
    build_vocab.addEventListener(MouseEvent.MOUSE_DOWN , startBtnDrag);
    build_spatial_rel.addEventListener(MouseEvent.MOUS E_DOWN, startBtnDrag);
    offer_clues.addEventListener(MouseEvent.MOUSE_DOWN , startBtnDrag);
    create_categories.addEventListener(MouseEvent.MOUS E_DOWN, startBtnDrag);
    help_follow_steps.addEventListener(MouseEvent.MOUS E_DOWN, startBtnDrag);
    enc_giving_dir.addEventListener(MouseEvent.MOUSE_D OWN, startBtnDrag);
    use_daily_act.addEventListener(MouseEvent.MOUSE_DO WN, startBtnDrag);

    // Button drag functions
    function startBtnDrag(evt:MouseEvent):void {
    if (currentContainer_1 < 7) {feedbackWrong_1[ ( currentContainer_1 + 1 ) ].alpha = 0};
    if (currentContainer_2 < 9) {feedbackWrong_2[ ( currentContainer_2 + 1 ) ].alpha = 0};
    if (currentContainer_3 < 7) {feedbackWrong_3[ ( currentContainer_3 + 1 ) ].alpha = 0};
    stage.addEventListener(MouseEvent.MOUSE_UP, buttonDrop);
    dragBtn = SimpleButton(evt.currentTarget);
    originLoc.x = dragBtn.x;
    originLoc.y = dragBtn.y;
    stage.addEventListener(MouseEvent.MOUSE_MOVE, buttonDrag);
    }
    function buttonDrag(e:MouseEvent):void {
    dragBtn.x = stage.mou***;
    dragBtn.y = stage.mouseY;
    }

    // Button drop functions
    function buttonDrop(evt:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, buttonDrag);
    stage.removeEventListener(MouseEvent.MOUSE_UP, buttonDrop);
    snapToContainer();
    dragBtn = null;
    originLoc = new Point();
    }

    function snapToContainer():void {
    // If inside the drop zone
    if (lg_container_1.hitTestObject(dragBtn)){
    // Check if answer is correct
    if (dragBtn.name == correctAnswers_1[dragBtn.name]) {

    // Set the current container and button position
    currentContainer_1++
    dragBtn.x = containers_1[currentContainer_1].x;
    dragBtn.y = containers_1[currentContainer_1].y;
    dragBtn.removeEventListener(MouseEvent.MOUSE_DOWN, startBtnDrag);
    }

    // If incorrect
    else {
    feedbackWrong_1[ ( currentContainer_1 + 1 ) ].alpha = 95;
    dragBtn.x = originLoc.x;
    dragBtn.y = originLoc.y;
    }
    }

    else if (lg_container_2.hitTestObject(dragBtn)) {
    // Check if answer is correct
    if (dragBtn.name == correctAnswers_2[dragBtn.name]) {

    // Set the current container and button position
    currentContainer_2++
    dragBtn.x = containers_2[currentContainer_2].x;
    dragBtn.y = containers_2[currentContainer_2].y;
    dragBtn.removeEventListener(MouseEvent.MOUSE_DOWN, startBtnDrag);
    }

    // If incorrect
    else {
    feedbackWrong_2[ ( currentContainer_2 + 1 ) ].alpha = 95;
    dragBtn.x = originLoc.x;
    dragBtn.y = originLoc.y;
    }
    }

    else if (lg_container_3.hitTestObject(dragBtn)) {
    // Check if answer is correct
    if (dragBtn.name == correctAnswers_3[dragBtn.name]) {

    // Set the current container and button position
    currentContainer_3++
    dragBtn.x = containers_3[currentContainer_3].x;
    dragBtn.y = containers_3[currentContainer_3].y;
    dragBtn.removeEventListener(MouseEvent.MOUSE_DOWN, startBtnDrag);
    }

    // If incorrect
    else {
    feedbackWrong_3[ ( currentContainer_3 + 1 ) ].alpha = 95;
    dragBtn.x = originLoc.x;
    dragBtn.y = originLoc.y;
    }
    }

    // If outside the drop zone
    else {
    dragBtn.x = originLoc.x;
    dragBtn.y = originLoc.y;
    }

    // Once the puzzle has been completed!
    if (currentContainer_1 + currentContainer_2 + currentContainer_3 == 23) {

    var timerNum:Number = 500; //1000= 1 second.
    var timer:Timer = new Timer(timerNum, 1); //1 = loops
    timer.addEventListener("timer", timerFunc); //listener to call timerFunc when iniciated
    timer.start(); //start timer
    function timerFunc(evt:TimerEvent):void{
    gotoAndPlay("Complete");
    }
    }
    }

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:34 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com