dcsimg
A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: Need urgent help

  1. #21
    Member
    Join Date
    Jun 2008
    Posts
    30
    lol I just finished making this...not pollished but at least you can release a little bit of stress.

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

  2. #22
    Junior Member
    Join Date
    Jun 2008
    Posts
    16
    actually i got 4 buttons in the screen i thought tat the same script can be used but can't

    btn1,btn2,btn3,btn4

    btn1 and 2 click textbox 1 appear
    btn1 and 3 click textbox 2 appear
    btn1 and 4 click textbox 3 appear
    btn2 and 3 click textbox 4 appear
    btn2 and 4 click textbox 5 appear
    btn3 and 4 click textbox 6 appear


    this is actually the real situation..thanks trugas for ur help alot...

  3. #23
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    Well, it took be about 20min, but I think I found it

    I don't think you could have found this on your own, not when you're new to AS3 (or even Flash!).

    I say, debug all of you, and let me know if I did manage to solve it
    Last edited by florianvanthuyn; 07-23-2009 at 07:44 AM.
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  4. #24
    Member
    Join Date
    Mar 2008
    Posts
    82
    Works for me Florian.
    But it got me thinking if the solution couldn't be simplified further.
    I was playing around with this kind of binary inspired approach.
    Each btn is assigned a number composed of 1s and 0s.
    These are then fed into a switch and every permutation has an individual number.
    It doesn't work though.
    Not sure if the end result would be any simpler, but feel free to poke holes in the code.
    I'd be interested to see if it could be made to work.

    PHP Code:
    stage.addEventListener(MouseEvent.CLICKwhichButton)

    var 
    btn1down:Number 1
    var btn2down:Number 10
    var btn3down:Number 100
    var btn4down:Number 1000

    var firstNum:Number 0
    var secondNum:Number 0
    var combinedNums:Number 0

    function whichButton(e:MouseEvent) :void {
        switch (
    this.target) {
            
    // Not sure what what parameter I need to feed in here. 'this.target' is clearly wrong.
            
    case btn1:
                if(
    firstNum == 0) {
                    
    firstNum btn1down
                
    }
                else {
                    
    secondNum btn1down
                    btnAdder
    ()
                }
                
            case 
    btn2:
                if(
    firstNum == 0) {
                    
    firstNum btn2down
                
    }
                else {
                    
    secondNum btn2down
                    btnAdder
    ()
                }
                
            case 
    btn3:
                if(
    firstNum == 0) {
                    
    firstNum btn3down
                
    }
                else {
                    
    secondNum btn3down
                    btnAdder
    ()
                }
                
            case 
    btn4:
                if(
    firstNum == 0) {
                    
    firstNum btn4down
                
    }
                else {
                    
    secondNum btn4down
                    btnAdder
    ()
                }
        }
    }

    function 
    btnAdder() :void {
        
    combinedNums firstNum secondNum;
        switch (
    combinedNums) {
            case 
    0011:
                
    text_box.text = ("message 1")
                break;
                
            case 
    0101:
                
    text_box.text = ("message 2")
                break;
                  
            case 
    1001:
                
    text_box.text = ("message 3")
                break;
                
            case 
    0110:
                
    text_box.text = ("message 4")
                break;
                
            case 
    1010:
                
    text_box.text = ("message 5")
                break;
                
            case 
    1100:
                
    text_box.text = ("message 6")
                break;
                
            default :
                
    text_box.text = ("try again")
        }
        
    firstNum secondNum 0

    Last edited by Trugas; 06-11-2008 at 08:08 PM.

  5. #25
    Junior Member
    Join Date
    Jun 2008
    Posts
    7
    If I understand what it is you're trying to do, I'd have the naming convention of the controls dictate the solution. So make use of the "1" of btn1, the "2" of btn2, etc., and the same for text_box1 and so on.

    Storing the necessary pairing in an array of arrays also is a simple and quick way to get at the data. Then use the natural index of the array to pair that with the last digit of the button name (actually last digit - 1, since arrays in AS are 0 indexed).

    PHP Code:
    var firstClicked:uint;
    var 
    counter:uint 0;
    var 
    arrays:Array;

    for (var 
    i:int=1i<=6i++) {
        
    this["text_box" String(i)].visible false;
    }

    //Use the natural  index of arrays and pair values
    //to adjust the visibility of the text boxes
    arrays = [[[2,1],[3,2],[4,3]], [[3,4],[4,5]], [[4,6]]];

    btn1.addEventListener("click"clickHandler);
    btn2.addEventListener("click"clickHandler);
    btn3.addEventListener("click"clickHandler);
    btn4.addEventListener("click"clickHandler);

    function 
    clickHandler(event:Event):void {
        if (
    counter == 0) {
            for (var 
    i:int=1i<=6i++) {
                
    this["text_box" String(i)].visible false;
            }
            
    firstClicked uint(event.currentTarget.toString().slice(-1));
            
    counter++;
        } else if (
    counter == 1) {
            var 
    secondClicked:uint uint(event.currentTarget.toString().slice(-1));
            if (
    firstClicked arrays.length) {
                
    counter 0;
                return;
            }
            var 
    arrLength:uint arrays[firstClicked 1].length;
            for 
    each (var arr:Array in arrays[firstClicked 1])
            {            
                if (
    arr[0] == secondClicked) {
                    
    this["text_box" arr[1]].visible true;
                    var 
    msg:String "text_box" arr[1].toString() + ": ";
                    
    msg += "You clicked Button " firstClicked " and Button " secondClicked ".";
                    
    this["text_box" arr[1]].text msg;
                    break;
                }
            }
            
    counter 0;
        }

    This assumes you have 4 instances of buttons named btn1 ... btn4 and 6 instances of text boxes named text_box1 ... text_box6 that will receive visibility based on which two buttons were clicked. To change the pairing, simply change the array containing the data. Note that you'd have to add a fourth array with its value pairs if you decide to have a sequence where the first click is btn4.

    TZiano
    Last edited by duodiscus; 06-11-2008 at 10:52 PM.

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