A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: How to leave a marker where the mouse has been clicked?

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    38

    How to leave a marker where the mouse has been clicked?

    I have created a movie that requires the user to click on two points on an image. I want a visual indication to appear (eg a marker of some sort) to appear on the first and second click. Is this possible?

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Make a dot by using brush tool or oval/circle tool, and convert it to a movieclip, and then remove it from the stage. Get inside your Libray (CTRL+L), locate the newly created movieclip, right-click it, press Properties (Linkage in Flash 8), click Advanced if you can't see anything, tick/check Export for Actionscript, and in the Identifier field, type in something like marker_mc and press OK. Then, use this code on your frame:

    Actionscript Code:
    i = 0;

    onMouseDown = function(){
        if(i < 2){
            attachMovie("marker_mc", "marker"+i, i, {_x:_xmouse, _y:_ymouse});
            i++;
        }
    }

    We make a variable i, set it to 0, and then increase it after each click. When you press the mouse down, if i is smaller than 2, we attach that dot movieclip to the mouse coordinates, thus making markers
    I am back, guys ... and finally 18 :P

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

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    38
    This makes absolute sense!!! Fantastic will give it a go and report back, many thanks!!!! (again!).

  4. #4
    Member
    Join Date
    Oct 2011
    Posts
    38
    That worked perfectly. I now need to insert a 'retry' button which will clear all markers, any idea how i could do this?

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Make a button, give it an instance name of for example, my_btn (click button, open Properties Panel, CTRL+F3, and type my_btn in the textfield labeled Instance), and then type this code on your frame, where the other code I provided is, after it:

    Actionscript Code:
    my_btn.onPress = function(){   
        for(a=0;a<i;a++){
            unloadMovie(_root["marker"+a]);
        }
        i = 0;
    }

    It will loop through all the created markers with for loop, and unload them
    I am back, guys ... and finally 18 :P

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

  6. #6
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,320
    Sorry to jump in but if using attachMovie then you should use removeMovieClip
    Code:
    my_btn.onPress = function(){    
        for(a=0;a<i;a++){
            removeMovieClip(_root["marker"+a]);
        }
        i = 0;
    }
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  7. #7
    Member
    Join Date
    Oct 2011
    Posts
    38
    This was working fine until i added the 'retry' button! NOt sure what i have done but variables that should reset and change on the click of a button are not doing....could someone give this a quick once over to see if there is anything obvious? There are three possible lots of feedback and these appear depedant upon where you click on the scan. Hopefully it will be self evident...
    Last edited by milanoli; 06-10-2012 at 03:08 PM.

  8. #8
    Member
    Join Date
    Oct 2011
    Posts
    38
    sorry 4 lots of feedback...correct, incorrect, yolk and sides.

  9. #9
    Member
    Join Date
    Oct 2011
    Posts
    38
    Just need to get the 'retry' button to reset all the variables....anyone?

  10. #10
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Look closely, you are making the two answer buttons invisible even when the player has marked wrongly. In the if/else statement when pressing submit button, make rump and crown's visibility set to TRUE and not false when the answer is incorrect, otherwise they won't be able to get correct after pressing Retry!
    I am back, guys ... and finally 18 :P

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

  11. #11
    Member
    Join Date
    Oct 2011
    Posts
    38
    I have altered as suggested but it still acts strangely once you have clicked on either 'Yolk_bt', 'sides_bt' or 'crown_bt' and I have no idea why. This is so close to working perfectly its really annoying....
    Last edited by milanoli; 06-10-2012 at 03:08 PM.

  12. #12
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    I don't understand what's wrong? Everything seems to be perfect, according to my comprehension, but please describe in details what is wrong, as I not a single clue on what that thing is supposed to be and what it's supposed to do :P
    I am back, guys ... and finally 18 :P

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

  13. #13
    Member
    Join Date
    Oct 2011
    Posts
    38
    Fair enough....

    There are four possible options:

    1. The user clicks on the ‘rump_bt’ and the ‘crown_bt’ buttons which changes both the ‘rump’ & ‘crown’ variables to 1. This is the correct interaction and should provoke the feedback text box to display ‘Correct’. This is working fine.

    2. If the user clicks on the ‘sides_bt’ button this is incorrect and should provoke the feedback text box to display ‘Incorrect. Remember you need to measure the length of the embryo.’ This works the first time but if you reset and click on a different option the same feedback is repeated no matter where you click (apart from if you get it right).

    3. If the user clicks on the ‘Yolk_bt’ button this is incorrect and should provoke the feedback text box to display ‘Incorrect. Oops! Looks like you have included the yolk sac in the measurement.’ This works the first time but if you reset and click on a different option the same feedback is repeated no matter where you click (apart from if you get it right).

    4. If user clicks anywhere else this is incorrect and should provoke the feedback text box to display ‘Incorrect.’ This works the first time but if you reset and click on a different option the same feedback is repeated no matter where you click (apart from if you get it right).

  14. #14
    Member
    Join Date
    Oct 2011
    Posts
    38
    Looks like I will just have to rebuild....

  15. #15
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    You know what, don't rebuild the whole thing, only the code:

    First of all, enter the Crooshair movieclip, click on the crosshair group in there, open Properties Panel, and change its X and Y to -8,2 to center it, because you do realize that the crosshair is not marked RIGHT on the spot where you click?

    Next, change all the buttons, crown, rump, yolk and sides to movieclips, you'll have to do this manually by making new movieclips with the same graphics, and the shapes that are on the HIT part of the button, should be on the first frames of the new movieclips, and they should have the instance names as their button counterparts - delete the buttons!

    After that, change all your code on the first frame of the Top layer, to the code ON THIS LINK

    or DOWNLOAD FIXED FLA FILE

    hope this is what you want
    I am back, guys ... and finally 18 :P

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

  16. #16
    Member
    Join Date
    Oct 2011
    Posts
    38
    Thank you so much for your time and effort on this. I have downloaded your file but can only get the 'incorrect' feedback to appear no matter where i click?

  17. #17
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    It's working just fine here

    Try removing these lines from the code:

    Actionscript Code:
    Yolk_bt._alpha = 0;
    rump_bt._alpha = 0;
    crown_bt._alpha = 0;
    sides_bt._alpha = 0;

    and then test your movie with the clickable areas visible - and it's not an error that the cursor/mouse should NOT change to a hand cursor when on the clickable screen. Now, try and click where you see the colored parts, and reply whether you still see Incorrect or not!

    EDIT: 700th post, YAY
    Last edited by Nig 13; 11-18-2011 at 08:22 AM.
    I am back, guys ... and finally 18 :P

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

  18. #18
    Member
    Join Date
    Oct 2011
    Posts
    38
    So, its appears that its just the sides buttons that are not prompting the correct feedback. Clicking where I have should display "Incorrect. Remember you need to measure the length of the embryo." Screen grab attached.
    Last edited by milanoli; 06-10-2012 at 03:08 PM.

  19. #19
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Oh, sorry, my fault. I increased the variables when touching them, so if both of the markers are on the same movieclip, in this case, sides_bt, then sides variable will be equals to 2, and in the submit button, it only checks if it's equals to 1. Sorry, my bad. Just change the code to THE CODE ON THIS LINK
    I am back, guys ... and finally 18 :P

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

  20. #20
    Member
    Join Date
    Oct 2011
    Posts
    38
    You are de man! Next time I am doing the bobsleigh run in Lillehammer I will buy you a beer!!!!!!!!! THANK YOU!!!!!!!!

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