views:

624

answers:

1

I added a standard Flash ComboBox component to my CS3 (AS2) project. It is part of one of my library symbols, not created on the stage.

I did not make any changes to the skinning, source code, etc. of the ComboBox.

When the user clicks on the ComboBox, the list drops down, the user uses the mouse to select an item, and that item is passed on to code that acts on it.

In the Flash IDE, everything works fine. But when I deploy this to a WebSite and view the Flash page via a web browser, when the user clicks on the value in the drop down list, a different value is selected and shown in the type-in box. (I am using Firefox 3.0.12 on a MAC, but our QA sees the problem in other browsers and versions). This same incorrect value is also passed to my change event callback.

The problem is apparent for Flash Player 9 and 10.

I tried two ways to get the value from the ComboBox.

a) Directly accessing the component to get the selection. When using this approach, if the user uses the keyboard to choose the value OR types in the number directly, it works in IDE and Browser. Only mouse selection fails.

   var num_pages_value:Number = Number(num_pages.num_pages_cb.selectedItem["data"]);

b) Using an event handler. When using this approach, the keyboard access to the ComboBox stops working. Here is how I set up the event handler:

var cb:ComboBox = num_pages.num_pages_cb;

// Without mx.events.EventDispatcher.initialize, the change event is never fired!!!
// Not in the docs. Looked so hard to find this out... mx.events.EventDispatcher.initialize( cb ); cb.addEventListener("change", this);

Here is the event handler itself.

function change(evt){ num_pages_value = Number( evt.target.selectedItem.label ); }

I suspect that the call to mx.events.EventDispatcher.initialize is what breaks the keyboard interaction, but without it my handler is never called. But neither approach lets the user select the value that they want. Pick a 7 and you get 9, pick a 3 and you get 6. And the value you get is not the same each time.

A: 

I'm trying to recreate the issue.

So far a simple test worked for me.

Here's my code:

import mx.controls.ComboBox;
import mx.controls.Label;

var cb:ComboBox = this.createClassObject(ComboBox,'cb',0);
for(var i:Number = 0 ; i < 10 ; i++) cb.addItem({label:'item'+(i+1)});

var l:Label = this.createClassObject(Label,'l',1,{_x:cb.width,text:'selection'});

var listener:Object = new Object();
listener.change = function(event:Object):Void{
 l.text = cb.selectedItem.label;
}
cb.addEventListener('change',listener);

I had Label and ComboBox in the library. The label changes using the mouse with the default generated HTML file from CS3.

For this test, I used:

  • Flash Player 10,0,32,18 Debugger
  • Mac OS 10.5.6
  • Firefox 3.5.6 (Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 GTB6)

HTH, George

George Profenza