dcsimg
A Flash Developer Resource Site

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

Thread: Need urgent help

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    16

    Need urgent help

    I have two buttons..btn1 and btn2 and a textbox(text_box).I need to press the first button than the next button in order to appear the word"hello" in the textbox.I must press btn1 and btn2 in order too see the word "hello" in the text box.I want to know the action script which i can place in the maintimeline so that i can use the actionscript for other buttons too.I hope u can help me out with this thank you.

  2. #2
    Junior Member
    Join Date
    Aug 2006
    Posts
    13
    You'll need to tie click event handlers for the buttons.

    Example: btn1.addEventListener(MouseEvent.Click, functionNameHere);

    One way to go about checking if both buttons have been clicked...

    You'll need to create 2 variables to hold the user interaction. If user clicks btn1, set the btn1 variable to true. If user clicks btn2, set the btn2 value to true. Then check to see if both variables are true and if so, print out your message to the textbox.

    Hope that helps.

  3. #3
    Junior Member
    Join Date
    Jun 2008
    Posts
    16
    Can u list down for me the actionscript...i am really new to flash...and i always hav error wen i do this...thank you.

  4. #4
    Member
    Join Date
    Jun 2008
    Posts
    30
    this was pretty simple stuff, really just need to make two buttons, set a var in each of them. use the eventlistener to call the function to check which was clicked and if the right sequence then display hello...just think about it for 5 mins.

    took me 10 mins to make this...

    http://georgew90.rack111.com/buttontest.swf

  5. #5
    Member
    Join Date
    Mar 2008
    Posts
    82
    Ok rasheedh, give this a go.
    Just make sure you have two buttons on your stage.
    and make sure you name the instances on the stage 'btn1' and 'btn2'
    PHP Code:
    btn1.addEventListener(MouseEvent.CLICKcheckBtn1);
    btn2.addEventListener(MouseEvent.CLICKcheckBtn2);
    //These lines will tell the buttons to 'listen' for when the user presses them
    //Then they will run the their associated check functions

    var text_box:TextField = new TextField();
    text_box.stage.stageWidth 2
    text_box
    .50
    addChild
    (text_box)
    // just creating the textfield here

    var btn1pressed:Boolean false;
    var 
    btn2pressed:Boolean false;
    //These two booleans will keep track of the state of the buttons
    // false = not pressed, true = pressed

    function checkBtn1(e:MouseEvent) :void {
        
    btn1pressed true;
        
    checkBothBtns();
    }
    // this function will wait to be called by the btn1 listener and then run the
    // checkBothBtns function


    function checkBtn2 (e:MouseEvent) :void {
        
    btn2pressed true;
        
    checkBothBtns();
    }
    // this function will wait to be called by the btn2 listener and then run the
    // checkBothBtns function

    function checkBothBtns () :void{
        
        if(
    btn1pressed == true && btn2pressed == true) {
            
    text_box.text "hello";
        }
        
    // this last bit will only run if both of the booleans are true


  6. #6
    Member
    Join Date
    Mar 2008
    Posts
    82
    lol, beat me to it Dukes90
    just realised that my example wont consider what order the buttons are pressed

  7. #7
    Member
    Join Date
    Jun 2008
    Posts
    30
    lol you wrote all the code for him...yea yours dosen't check the button order, only works for two buttons.

  8. #8
    Member
    Join Date
    Mar 2008
    Posts
    82
    Ok, just slapped this together, a few changes made.

    PHP Code:
    btn1.addEventListener(MouseEvent.CLICKcheckBtn1);
    btn2.addEventListener(MouseEvent.CLICKcheckBtn2);

    var 
    text_box:TextField = new TextField();
    text_box.stage.stageWidth 2
    text_box
    .50
    addChild
    (text_box)

    var 
    btn1pressed:Boolean false;

    function 
    checkBtn1(e:MouseEvent) :void {
        
    btn1pressed true;
    }

    function 
    checkBtn2 (e:MouseEvent) :void {
        if(
    btn1pressed == true) {
            
    bothBtnsPressed();
        }
    }

    function 
    bothBtnsPressed () :void{
        
    text_box.text "hello";

    See how you go with that.

  9. #9
    Member
    Join Date
    Jun 2008
    Posts
    30
    hehe i would just draw a dynamic box along with the two buttons and cut the code down to this. ... I feel like we just did his homework for him

    Code:
    btn1.addEventListener(MouseEvent.CLICK, checkBtn1); 
    btn2.addEventListener(MouseEvent.CLICK, checkBtn2); 
    var btn1pressed:Boolean = false; 
    
    function checkBtn1(e:MouseEvent) :void { 
        btn1pressed = true; 
    } 
    
    function checkBtn2 (e:MouseEvent) :void { 
        if(btn1pressed == true) { 
            text_box.text = "hello";
        } 
    }
    Last edited by dukes90; 06-11-2008 at 12:49 AM.

  10. #10
    Member
    Join Date
    Mar 2008
    Posts
    82
    nicely done.
    Ahh, your probably right about that.
    But we were all noobs once looking for help...
    I still am!

  11. #11
    Junior Member
    Join Date
    Jun 2008
    Posts
    16
    Hi guys thanks alot for ur help..but i am having a prob wen i use the actionscript.The line which has problem is below.I am using flash cs3.Any idea y is it??Anyway thanks alot for ur help peeps!!!!

    function checkBtn1(e:MouseEvent) :void {
    function checkBtn2 (e:MouseEvent) :void {

  12. #12
    Junior Member
    Join Date
    Jun 2008
    Posts
    16
    Hi guys thanks alot for ur help..but i am having a prob wen i use the actionscript.The line which has problem is below.I am using flash cs3.Any idea y is it??Anyway thanks alot for ur help peeps!!!!

    function checkBtn1(e:MouseEvent) :void {
    function checkBtn2 (e:MouseEvent) :void {

  13. #13
    Member
    Join Date
    Jun 2008
    Posts
    30
    ...there nothing wrong with the code...you didn't name the buttons correctly did you? lol or maybe ctrl c and ctrl v didn't work???
    Last edited by dukes90; 06-11-2008 at 03:21 AM.

  14. #14
    Junior Member
    Join Date
    Jun 2008
    Posts
    16
    Hey yea i got it to wrk haha...thanks alot man...it was a great help...but another doubt....can i use the same action script for now like i click btn1 and btn3 and a word "bye" come out in the text box with the btn1 and btn2 action script already in the maintimeline??

  15. #15
    Junior Member
    Join Date
    Jun 2008
    Posts
    16
    how to put the start button???

  16. #16
    Junior Member
    Join Date
    Jun 2008
    Posts
    16
    sorry abt the start button i am sorry..i jus want to know abt the btn3...

  17. #17
    Member
    Join Date
    Mar 2008
    Posts
    82
    Come on rasheedh, all the clues you need are there in the code we've posted.
    We can't do the whole thing for you, least of all because you wont learn a thing!
    At least give it a go mate. If you get stuck just post what you tried.

  18. #18
    Junior Member
    Join Date
    Jun 2008
    Posts
    16
    i am jus stressed up...i am going wrong everywhere.....oki itried this

    Firstly in 1 layer i put in two buttons and used ur actionscript

    btn1.addEventListener(MouseEvent.CLICK, checkBtn1);
    btn2.addEventListener(MouseEvent.CLICK, checkBtn2);
    var btn1pressed:Boolean = false;

    function checkBtn1(e:MouseEvent) :void {
    btn1pressed = true;
    }

    function checkBtn2 (e:MouseEvent) :void {
    if(btn1pressed == true) {
    text_box.text = "hello";
    }
    }


    And in the second layer i created another btn3 and btn4 and text_box2

    btn3.addEventListener(MouseEvent.CLICK, checkBtn3);
    btn4.addEventListener(MouseEvent.CLICK, checkBtn4);
    var btn1pressed:Boolean = false;

    function checkBtn3(e:MouseEvent) :void {
    btn3pressed = true;
    }

    function checkBtn4 (e:MouseEvent) :void {
    if(btn3pressed == true) {
    text_box2.text = "hello";
    }
    }


    And now i have to interlink btn1 and btn3 for something to come out in the text_box3..i add in the same script on another layer but it seems i cannot repeat the button number again...need help here....

  19. #19
    Member
    Join Date
    Mar 2008
    Posts
    82
    Ok, No need to stress. Let me try and understand the situation.
    Your previous post told a different story.
    Sounds like you need three buttons up on the screen at once.
    Then you want to have different messages appearing in the same
    text box depending on the order that the buttons are pressed, correct?

  20. #20
    Member
    Join Date
    Jun 2008
    Posts
    30
    you have to think for yourself...you can't just use the code for that simple two button check for a three button system...you have to adapt it use if else statments.

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