A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How do you check if the user hasn't made a selection on a combo box?

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    129

    How do you check if the user hasn't made a selection on a combo box?

    Just as the title says really! How do you check if the user hasn't made a selection on a combo box? Here's what I've tried, to no avail:

    Code:
    tShirtBuy.addEventListener(MouseEvent.CLICK, sendShirtToCheckout);
    
    function sendShirtToCheckout (evt:MouseEvent):void {
    	if (tShirtColour.selectedItem.value == "" || tShirtSize.selectedItem.value == "") {
    		trace("worked!")
    	} else {
    		trace("fail!")
    	}
    }
    which gives the error:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at indoorshredwebsite_fla::shopmc_17/sendShirtToCheckout()

  2. #2
    AS2 intolerant person
    Join Date
    Jan 2009
    Location
    Swansea
    Posts
    352
    normally combo boxes in all programs show a default option. you could make the first option a: ' - ' for example.
    then the selected index by default would be 0.

    then do a check like this:

    Code:
    if(tShirtColour.selectedIndex == 0) {
    
    }
    thats how its done in javascript, so it should be the same.

    flos

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    That works marvellously, thanks flosculus.

    I just did something slightly different to make it even better. Instead of adding the " - " label, I set the "prompt" value in the component inspector to " - " and used:

    Code:
    if(tShirtColour.selectedIndex == -1) {
    
    }
    Thanks once again!

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