A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Passing parameters

  1. #1
    Junior Member
    Join Date
    Jan 2007
    Location
    Blue Mountains, Australia
    Posts
    21

    Passing parameters

    Hi,
    Its been a long time since I've used koolmoves and still new to AS3. Trying to work out how to use the km components.
    I'm trying to get the results from a series of checkboxes but rather than outputting the results straight away, I
    want to to show the results when pressing the submit button.

    I've got the general idea but I'm having problems on how to pass the data (outcheck1, outcheck2 and outcheck3)
    to a function. I think I'm not passing parameters properly.

    Anyway the following code is listed. Thanks in advance (by the way there may be more of these basic questions coming up
    but I'll try to make an attempt to solve them before seeking help!)

    import km.core.*;
    import km.components.*;

    checkbox1.setProperties({x:50, y:50, checked:false});
    checkbox1.text = 'Checkbox 1';
    checkbox1.onChange = function(){
    var outcheck1:String = this.checked ? 'checkbox 1 checked' : 'checkbox 1 unchecked';
    txt2.text = outcheck1;
    }
    addChild(checkbox1)


    checkbox2.setProperties({x:50, y:70, checked:false});
    checkbox2.text = 'Checkbox 2';
    checkbox2.onChange = function(){
    var outcheck2:String = this.checked ? 'checkbox 2 checked' : 'checkbox 2 unchecked';
    txt2.text = outcheck2;
    }
    addChild(checkbox2)


    checkbox3.setProperties({x:50, y:90, checked:false});
    checkbox3.text = 'Checkbox 3';
    checkbox3.onChange = function(){
    var outcheck3:String = this.checked ? 'checkbox 3 checked' : 'checkbox 3 unchecked';
    txt2.text = outcheck3;
    }
    addChild(checkbox3)

    // output checkbox combinations

    pushbutton1.addEventListener(MouseEvent.MOUSE_DOWN ,outputshow);

    function outputshow(e:MouseEvent):void {
    var result:String = outcheck1 + outcheck2 + outcheck3;
    txt1.text = result;
    }

  2. #2
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    It's probably the variable scope.
    If you define a variable inside a function, it is local to that function. Outside of the function it's not visible.

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    You should try running the debug version of flashplayer when testing, it makes sorting this kind of thing out much easier..

    When I run your code it's as Wilbert suggest I get an error that outcheck1 is not definded

    If you want to access variables outside of the function you just declare (create) them before the function

    Code:
    import km.core.*;
    import km.components.*;
    
    var outcheck1:String
    var outcheck2:String
    var outcheck3:String
    
    checkbox1.setProperties({x:50, y:50, checked:false});
    checkbox1.text = 'Checkbox 1';
    checkbox1.onChange = function(){
    outcheck1 = this.checked ? 'checkbox 1 checked' : 'checkbox 1 unchecked';
    txt2.text = outcheck1;
    }
    addChild(checkbox1)
    
    
    checkbox2.setProperties({x:50, y:70, checked:false});
    checkbox2.text = 'Checkbox 2';
    checkbox2.onChange = function(){
    outcheck2 = this.checked ? 'checkbox 2 checked' : 'checkbox 2 unchecked';
    txt2.text = outcheck2;
    }
    addChild(checkbox2)
    
    
    checkbox3.setProperties({x:50, y:90, checked:false});
    checkbox3.text = 'Checkbox 3';
    checkbox3.onChange = function(){
    outcheck3 = this.checked ? 'checkbox 3 checked' : 'checkbox 3 unchecked';
    txt2.text = outcheck3;
    }
    addChild(checkbox3)
    
    // output checkbox combinations
    
    pushbutton1.addEventListener(MouseEvent.MOUSE_DOWN ,outputshow);
    
    function outputshow(e:MouseEvent):void {
    var result:String = outcheck1 + outcheck2 + outcheck3;
    txt1.text = result;
    }

  4. #4
    Junior Member
    Join Date
    Jan 2007
    Location
    Blue Mountains, Australia
    Posts
    21
    It was as simple as that? Thank you very much Wilbert and Blanius !
    Maybe I need to learn to crawl before I can run and learn the fundamentals.
    Cheers!
    Carlo

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