flash cs4 combobox component totally ignore styles and events

I have simple combobox component in flash cs4, I try to add and event listener like this

mycombo.addEventListener(Event.ADDED_TO_STAGE, added);

function added(e:Event):void
{
trace("HI");
}

never get called even if I have the component in the stage manually or via AS, but if I add a listener to MouseOver it works, why the ADDED_TO_STAGE event don't work, also I have a problem with the textFormat style if I use

mycombo.setStyle("textFormat", tf);//suppose tf is a TextFormat object

doesn't work too, but if I put that line inside the MouseOver event it work's why?? please help thanks!!


I had the same situation and found that if I created the component in ActionScript rather than through the visual design tool then making changes to the component in code worked. So, I deleted the object from the .FLA file and created it in the associated .AS file instead like this.

var ddlQF:ComboBox=new ComboBox();
this.addChild(ddlQF);
ddlQF.move(444,191);
ddlQF.setSize(284,40);
ddlQF.rowCount=10;
var myFormat:TextFormat = new TextFormat();
myFormat.font = "Georgia";
myFormat.size=16;
ddlQF.setStyle("textFormat",myFormat);

Problem 1 Reason:

It appears that ADDED_TO_STAGE can occur before the trigger.

From https://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html#ADDED_TO_STAGE

The DisplayObject instance being added to the on stage display list, either directly or through the addition of a sub tree in which the DisplayObject instance is contained. If the DisplayObject instance is being directly added, the added event occurs before this event.

Problem 2 Reason:

Again, I believe the event is occurring before the event trigger. Thus the style never gets processed.

链接地址: http://www.djcxy.com/p/17846.html

上一篇: 在AS3中的类定义文件中创建元素(Flash CS4)

下一篇: flash cs4 combobox组件完全忽略样式和事件