A Flash Developer Resource Site

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

Thread: [RESOLVED] Pressing movieclips in a specific order/sequence

Hybrid View

  1. #1
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971

    resolved [RESOLVED] Pressing movieclips in a specific order/sequence

    Hello, im kinda lost (i am completely lost, i should say xD )

    I want to say HI to everyone on this great forum,specially the fews I remember like fruitbeard, Nig13, Alloy Bacon, Whispers.

    Now, i have this question for months or years, i tried to help someone in this forum with his/her "Pressing movieclips in a sequence or order" query, and I overloaded my brain trying hehe.

    This month, i finally achieved it , but then i noticed a flow in it.
    I used this method (remember i'm not an advanced actionscript programmer :P i am mostly like average/intermediate)

    In all the four moviclips (MC1, MC2, MC and MC4) i have this:
    PHP Code:
    //MC2 is the first moviclip of the sequence
    MC2.onPress = function(){
    myTxtField.text +=1//adds number "1"in the text field
    checkOrder();
    }

    //MC3 is the second moviclip of the sequence
    MC3.onPress = function(){
    myTxtField.text +=3//adds number "3"in the text field
    checkOrder();
    }

    //MC1 is the third moviclip of the sequence
    MC1.onPress = function(){
    myTxtField.text +=3//adds number "3"in the text field
    checkOrder();
    }

    //MC4 is the fourth movieclip of the sequence
    MC4.onPress = function(){
    myTxtField.text +=4//adds number "4"in the text field
    checkOrder();

    The order in which we must press the movieclips in order to succeed to frame 2, is 1- MC2, 2- MC3, 3- MC1 and 4- MC4

    Then i have this function checkOrder:

    PHP Code:
    function checkOrder(){

    //if the numbers inserted  in the texfield by pressing the movieclips in the correct order is equal to "1234"...

    if (myTxtField.text== "1234" && myTxtfield.text.length ){

    gotoAndStop(2); //SUCCESS
    }

    else {

    //empty the text field, so you can keep trying other orders
    myTxtField.text="" 

    That actually works perfectly. The flow comes when , let's say, I press on MC2, it inserts "1"in the text field...but if I decide to start pressing the buttons in the correct order from there, it would be "11234" because MC2 was already pressed once before starting the pressing sequence. This happens, well, naturally, as let's say the user/player pressed MC2 once by mistake, or the player press it, then something calls his/her attention, and they want to start the sequence again, then the text field has value already. I thought in adding a "reset"button so the user resets everything and they must not have any problems.

    But I thought, lets say instead of using 4 Movieclip buttons, I have this "PIANO" and its keys, the user must be able to continously check for the correct pressing orders of a song in order to succeed. Then i thought about using something like this:

    PHP Code:
    var IS:String;

    MC1.onPress=function(){

    //if the variable IS is undefined, that means no movieclip have been pressed first

    if(this.IS==undefined){

    this.IS="FirstPress";  //Give it the first place

    }

    //else if MC2 or MC3 or MC4 have the first place
    else if (MC2.IS=="FirstPress" || MC3.IS=="FirstPlace" || MC4.IS=="FirstPlace"){

    this.IS="SecondPlace";  //Give it the second place instead
    }

    }; 
    ...and so on... but I didn't succeed that way :/

    I finally thought about using an array but i am too much stressed hehe... hope someone can give me some light as I always say

    ************************
    For the rest, well, i'm sad with the obviously eventually dead of actionscript, due to the born of the HTML5. I am learning HTML5 because i'm developing web sites that need to be displayed in all devices, and android stopped giving support to Flash player, and apple have never gave support to it so... that's what i'm doing right now, focus on HTML5, but making some flash apps, games, etc. I finally mastered the arrays, the for loops, the switch statement, the functions with arguments passed externally, and a lot of things ^_^yay

    (Nig13 i have to show you my update of the game "Esk�pate", for which you helped me a lot, with the for loop to load all the rooms from the shared object, storing the volume state (Mute/Unmute) in a shared object, and all the help you guys (also fruitbeard) have gave to me ^_^i'm very thankful)

    Hope you are all doing great
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I forgot some details in the checkOrder function lol... it was supposed to say:
    PHP Code:
    if (myTxtField.text== "1234" && myTxtfield.text.length ){ 
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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

    Angle, you do not have a "2" in your sequence so therefore it would never == "1234", maybe something like so,
    PHP Code:
    stop();

    var 
    SetSize:Number 4;
    var 
    Winline1:String "1234";

    for (
    1<= SetSizei++)
    {
        
    this["MC" i].Num i;
        
    this["MC" i].onPress = function()
        {
            
    myTxtField.text += this.Num;
            
    checkOrder();
        };
    }

    function 
    checkOrder()
    {
        if (
    myTxtField.text.length >= SetSize)
        {
            if (
    myTxtField.text == Winline1)
            {
                
    gotoAndStop(2);
                
    trace("Yes");
            }
            else
            {
                
    myTxtField.text "";
                
    trace("No");
            }
        }


    Last edited by fruitbeard; 08-24-2013 at 09:22 AM.

  4. #4
    Junior Member
    Join Date
    Jul 2012
    Posts
    14
    Hi! Maybe this is not the correct way to do it, but I think it´s what you need and it works!

    1234.fla

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Quote Originally Posted by fruitbeard View Post
    Hi,

    Angle, you do not have a "2" in your sequence so therefore it would never == "1234", maybe something like so,
    PHP Code:
    stop();

    var 
    SetSize:Number 4;
    var 
    Winline1:String "1234";

    for (
    1<= SetSizei++)
    {
        
    this["MC" i].Num i;
        
    this["MC" i].onPress = function()
        {
            
    myTxtField.text += this.Num;
            
    checkOrder();
        };
    }

    function 
    checkOrder()
    {
        if (
    myTxtField.text.length >= SetSize)
        {
            if (
    myTxtField.text == Winline1)
            {
                
    gotoAndStop(2);
                
    trace("Yes");
            }
            else
            {
                
    myTxtField.text "";
                
    trace("No");
            }
        }


    Hello fruitbeard! hope you're doing great my friend.

    It was supposed to be a "2", but i typed it wrong hehe, there are 2 movieclips with the samen number "3".
    PHP Code:
    //MC3 is the second moviclip of the sequence 
    MC3.onPress = function(){ 
    myTxtField.text +=[B]3[/B]; //it was supposed to be "2"not "3" my mistake :P
    checkOrder(); 

    And about your fla's , thank you very much, i will open it when i get home, i dont have internet since 3 months ago sniff sniff.

    You can inbox me, tell me what are you up to? C'ya
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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

    The sequence in this example is "1234";

    CS5:

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

    I'm not sure why you don't keep things more simple in the beginning, by making mc1 = 1, mc2 = 2, mc3 = , mc4 = 4 and then just change the sequence needed to be used.
    Anyway I'm sure you will see this from the example.

    Fruit

  8. #8
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Yeah, i will take that in consideration hehe.

    Look, this is the idea, the concept which i'm refering to http://www.youtube.com/watch?v=9b9R8kMg-vo It's from a 80's nintendo game, it's a piano/organ, and you are always pressing buttons, and you decide when to begin pressing the right buttons. In your fla's and in my fla, if we for example press Mc1, then "1" is entered in the textfield. But if we decide to start again the secuence, and press the buttons in the correct order, it will fail, because there is number 1 already in the textfield. In this game's piano/organ, you press key "F" for example, then you can begin the secuence from there and succeed ( Piano Keys order: Key C, Key E, Key G, Key F, Key C, Key E). It doesn't matter if you pressed 2 or 3 wrong keys, you can always start the right secuence from where you left it, without having to press a button to reset, or without a message that tells you "You have pressed 5 wrong keys, so you have to start the secuence again".

    I think i need to make that when pressing a button, "reset" its value each time (value removed from the textfield), but only if pressing the right buttons in the right order, the values aren't removed from the textfield. Example:

    1- Pressed MC1, MC1 is not the first button of the secuence, so , remove its value ("1") from the textfield.
    2- Pressed MC2, MC2 IS the first button of the secuence, so, leave the value entered ("1").
    3- Pressed MC1 again, MC1 is not the second button of the secuence, so, reset everything (remove all the values from the textfield ("1" and "1").
    4- Pressed MC2, again, MC2 is the first button of the secuence, so, leave the value "1" in the textfield.
    5- Pressed MC3, MC3 is the second button of the secuence, so, leave the value "2"in the textfield.
    6- Pressed MC1, MC1 is the third button of the secuence, so, leave the value "3"in the textfield.
    7- Pressed MC4, MC4 is the fourth button of the secuence, so, leave the value "4"in the textfield and you SUCCEED.


    That is why i need to achieve, hehe. Hope i'm explaining myself well. Thank you!
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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

    Now that involves slightly more, but I think you have enough food for thought in the file I attached, maybe post your file when you have achieved some more.

  10. #10
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Well, i will post the solution later...because i don't have time right now
    But I achieved it (i can sleep in peace now xD)

    And I unbelieveable made it with almost NO SCRIPT at all! With just önPresses and frame navigating xD
    Obviously I made some tweeks in the way the buttons are pressed according to the frame they are...

    but here is the fixed .fla
    http://www.mediafire.com/download/6r..._Angel_Hdz.zip


    Also I added some "cool stuff" like fade in, sound, and pressing limiters. I hope the friend who initially started all this (the this forum's user from whom I inspired, he started a thread long time ago, about Pressing buttons in a sequence or order) see this thread and it helps him/she too.


    Last edit: After having success with this issue, I realized I can make the same thing with variables and if statements (using variables instead of the frames, var myFrame=1, if (myFrame==1) {thisButton.onPress=function {myFrame=2; } } ), and also I can make it with javascript and other languages that include if statements and variables
    Last edited by angelhdz; 09-03-2013 at 04:29 PM.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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

    Angel, although it works you have limited yourself to the 4 or so frames that you have in the swf and therefore unable to adjust the order at any time easily because it relies on the fact that you go the next frame and so on.

    But if that's all you wanted then fine, well done.

    Edit: would like to see the javascript version and maybe any of the other languages you have done it in too.

  12. #12
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Here is the result of the idea that i was inspired from (Nintendo 1990 Star Tropics game)

    Fruitbeard: I will change the frames method with the variables + if statements method, so i think it will help me to adjust the order any time easily because i would be number variables! Thanks for the idea that's my next goal (one of many goals hehe)

    http://www.mediafire.com/?n79ss7vin9x6a58
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  13. #13
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    me gusta

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

    Why don't you attach the *.fla file too Angel and we can try and make it more efficient and easier to change at any given time, as you still seem to be using many frames with many different copies of the same buttons all with different coding on them.

  15. #15
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Let me make quickly the variables & if statements version, and upload both .fla's
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  16. #16
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    HYi,

    Mess around with this Angel, CS5

  17. #17
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Here you go! here is the .fla CS5 Variables Frames + If/Else version
    http://www.mediafire.com/?9b2x86wl532ma4l

    Gonna check your fla thanks for your time
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  18. #18
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I think I would be very close of doing something like that fruitbeard haha, but you're awesome, thanks. You took my engine to another level!!!

    (there is a little issue with your script, when you success, and press the back button, the app goes to its locked state, and that's suppose to happen only when the tries ran out! but i know how to fix it hehe because i understand your script perfectly)


    ***************************
    I'm mastering the art of the arrays and the for loops, in fact, I used it yesterday for one of the games im developing "Eskápate" (an escape the room like game) in which I removed the hand cursor to ALL the items, buttons and movieclips of all the stages/levels with a simple function loaded at the first frame (i have a little issue with one specific level, level 4, in which the items don't respond to the removingHand function, but if I add the "mybutton.useHandCursor=false" script directly to the level 4 frame, it works... weird because it works in all other stages with buttons inside movieclips) this is my script:
    PHP Code:
    var myArray:Array = [];    
    //remove hand cursor to all items
    function removeHand(){


    for (
    j=08j++)
    {
    myArray.push("button"+[j]);


    }
        
    myArray.push("florero");
        
    myArray.push("breakwindow");
        
    myArray.push("windowMC.windoW.buttong");
        
    myArray.push("ladderMC.ladder")   //these two movieclips are on frame level 4, all the other items in the array 
        
    myArray.push("ladderMC.slideR");  //are on their  respective frames 
        
    myArray.push("fakewall");
        
    myArray.push("pianoMC");
        
    myArray.push("trash");
        
    myArray.push("Screens.hit");
        
    myArray.push("Screens.closeMC1");
        
    myArray.push("Screens.closeMC2");
        
    myArray.push("ductape");
        
    myArray.push("bombMC.bomb.bombHIT");
        
    myArray.push("bombMC.bomb.bombBTN");
        
    myArray.push("cdisc");
        
    myArray.push("radioMC.radioBTN");
        
    myArray.push("vol_trigger");
        
    myArray.push("breakwindow2");
        
    myArray.push("glassMC");
        
    for (
    j=0myArray.lengthj++)
    {
        
    this[myArray[j]].useHandCursor=false;
        
    }
    }; 
    and in the actions layer of each stage frame i have this:
    PHP Code:
    //Initialize removeHand(); 
    But that's another topic hehe but now i understand the arrays, and split, push, etc. and controlling multiple buttons/movieclips with one simple function + array etc...see ya
    Last edited by angelhdz; 09-10-2013 at 05:32 PM.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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

    Attach your *.fla , I'm not going to try and recreate your file.

  20. #20
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Fruitbeard, i'm not asking you to make thinks for me haha! I was just talking about stuff I'm working on...
    But yeah, next time i will upload a minimized version of the game, so you can help me to find where the issue hides

    And talking about this topic/thread, i fixed your .fla already. I only had to add the "DoFade();" at first lines of the script, to call that function, so it is not "locked" when you start playing the movie. Now i'm working in the shared object thing, to save the Attempts, so let's say I open the movie, i have 5 chances, then I close the movie and reopen it, i will always have "5"chances, so you would be able to try and try once and again until guessing the correct order. So i have to save the attempts in the shared object, and when opening the movie, load the saved attempts and check if it is equal to 0, then do the LOCK function. If not, then do the DoFade and SetUp funcions. I will work on that today if I have enough time. Take care and hope you are doing great
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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