A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Booleans and Movieclip Control

  1. #1
    Member
    Join Date
    Dec 2003
    Posts
    99

    Booleans and Movieclip Control

    How do I use a Boolean to control a movie clip? I am trying to create a code input to where if the the 4 dynamic text fields equal a certain code a light is displayed.

    the 4 dynamic text fields are labled cv1, cv2, cv3, cv4

    there is an UNLOCK button which when pressed makes the light go green if the following numbers are present in the Dynamic Text fields (the numbers are 9337)

    so this is my code:

    on (release) {
    var codeiscorrect:Boolean;
    if(cv1==9, cv2==3, cv3==3, cv4==7) {
    codeiscorrect=true;
    }else{
    codeiscorrect=false;
    }
    }

    what code do i need to do this? or is there anywhere where i can learn about Booleans?

    thanks for any help i can recieve
    This is so non hanous!

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    you almost had it...
    code:

    on (release) {
    var codeiscorrect:Boolean;
    if(cv1==9 && cv2==3 && cv3==3 && cv4==7) {
    codeiscorrect=true;
    }else{
    codeiscorrect=false;
    }
    }



    you can even then tell what field is incorrect too..if you wanted to.

  3. #3
    Member
    Join Date
    Dec 2003
    Posts
    99
    ok i got the code sorted for the code:

    on (release) {
    var codeiscorrect:Boolean;
    if(cv1==9 && cv2==3 && cv3==3 && cv4==7) {
    codeiscorrect=true;
    _root.gotoAndPlay(2);
    }else{
    codeiscorrect=false;
    }
    }

    however i have 4 lights (white when off, and green when on). So say if 9336 was entered as the code then three lights would go on. There is a light associated to each digit of the 4 digit pin.

    How would i make each light go on if the correct digit is entered?

    I tried this code:

    on (release) {
    var codeiscorrect:Boolean;
    if(cv1==9 && cv2==3 && cv3==3 && cv4==7) {
    codeiscorrect=true;
    _root.gotoAndPlay(2);
    _root.cva1.gotoAndPlay(2);
    _root.cva2.gotoAndPlay(2);
    _root.cva3.gotoAndPlay(2);
    _root.cva4.gotoAndPlay(2);
    }else{
    codeiscorrect=false;
    }
    }

    but the lights only go on when all the 4 digits are entered not when i get one digit right that is associated with the digit.

    Any help is appreciated
    This is so non hanous!

  4. #4
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    The way your if statement is structured, all the conditions must be true in order for the code to fire. If you want them to fire individually, seperate each variable into it's own if statement.

  5. #5
    Member
    Join Date
    Dec 2003
    Posts
    99
    would this be right then?:

    on (release) {
    var codeiscorrect:Boolean;
    var light1:Boolean;
    var light2:Boolean;
    var light3:Boolean;
    var light4:Boolean;

    if(cv1==9) {

    light1=true;
    _root.cva1.gotoAndPlay(2);

    }else{

    codeiscorrect=false;
    light1=false;
    }
    if(cv2==3) {

    light2=true;
    _root.cva2.gotoAndPlay(2);

    }else{

    codeiscorrect=false;
    light2=false;
    }
    if(cv3==3) {

    light3=true;
    _root.cva3.gotoAndPlay(2);

    }else{

    codeiscorrect=false;
    light3=false;
    }
    if(cv4==7) {

    light4=true;
    _root.cva4.gotoAndPlay(2);
    }else{

    codeiscorrect=false;
    light4=false;
    }
    if (cv1==9 && cv2==3 && cv3==3 && cv4==7) {

    codeiscorrect=true;
    _root.gotoAndPlay(2);
    }
    }

    i am getting confused. Once the i get the digit right the light goes green. But once i press the unlock button again it goes white even tho the digit is correct. I tried a gotoAndStop but once the digit is wrong it stays green and doesnt go back to its off state which is white.

    any help?
    This is so non hanous!

  6. #6
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    how about uploading your fla?
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  7. #7
    Member
    Join Date
    Dec 2003
    Posts
    99
    uploaded fla and swf
    Attached Files Attached Files
    This is so non hanous!

  8. #8
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    sorry need it in mx 2004 format..
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  9. #9
    Member
    Join Date
    Dec 2003
    Posts
    99
    new upload
    Attached Files Attached Files
    This is so non hanous!

  10. #10
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Ok cheers..now can u explain from scratch exactly what functionality u are looking for and how it should work:

    (1) what is supposed to happen when i enter the correct code and click unlock..
    (2) what is supposed to happen when i enter the incorrect code and click unlock
    (3) when are the lights supposed to be green and when are they supposed to be white?
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  11. #11
    Member
    Join Date
    Dec 2003
    Posts
    99
    well the unlock code is 9337

    1) i want the unlock code to unlock a vault and go to a certain level
    2) when you enter the incorrect code a sound will happen
    3) the light goes green when a correct part of the code has been entered. It
    should stay green when the correct digit is present but will stay white if
    incorrect digit is present (e.g. not matching 9337)

    i hope this explains it well enough for you and thank you for taking a look
    This is so non hanous!

  12. #12
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Ok ive attached working version of the file. A few points to note:

    (1) Ive removed all the actions from within the buttons themselves as this is not good practice. Instead all the code is in frame 1.

    (2) Ive given all your textfields instance names t0, t1, t2, t3 and controlling them by their instance names instead of putting a value in the var field in the property panel.(forget that even exists IMO).. also the buttons have been named plus0, plus1, plus2 , plus 3 and well as the minus buttons...
    its a good idea to try naming your instances begginning with index 0 rather than 1. this is because is many applications u will be using arrays and since arrays start with index 0, it just makes life easier...

    (3) the code in frame 1 can be really compacted and condensed into maybe hafl as many lines by using loops etc(however i have not used loops, because that would make it harder for u to see whats going on)..

    anyway hope it helps...
    Last edited by silentweed; 08-23-2007 at 09:44 AM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  13. #13
    Member
    Join Date
    Dec 2003
    Posts
    99
    fantastic! this is now helped me enough to continue on with the project. Thank you so much!
    This is so non hanous!

  14. #14
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    yw
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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