开发者

Editing a ComboBox in AS3

I am having problems editing a ComboBox in AS3. Can anyone please tell me why my ComboBox disappears? Thanks to all that help in advance.


import fl.controls.ComboBox;
import fl.data.DataProvider;


var typeTextFormat:TextFormat = new TextFormat();
typeTextFormat.color = 0xFFCC00;
typeTextFormat.size = 11;
typeTextFormat.font = "Verdana";


var typeButton:Sprite = new Sprite();
addChild(typeButton);
typeButton.graphics.beginFill(0x000000);
typeButton.graphics.drawRect(0, 0, 109, 32);
typeButton.graphics.endFill();
typeButton.alpha = 0.75;
typeButton.filters = [new GlowFilter(0x000000,0.5,0,12,1,1,false,false)];


var workList:Array = new Array(
    { label: "All Work", data: "all" }开发者_JS百科,
        { label: "Work1", data: "w1" },
        { label: "Work2", data: "w2" },
        { label: "Work3", data: "w3" }
    );


var menu1:ComboBox = new ComboBox();
addChild(menu1);

menu1.setStyle("upSkin", typeButton);
menu1.setStyle("overSkin", typeButton);
menu1.setStyle("downSkin", typeButton);
menu1.setSize(109, 32);

menu1.dropdown.setRendererStyle("upSkin", typeButton);
menu1.dropdown.setRendererStyle("overSkin", typeButton);
menu1.dropdown.setRendererStyle("downSkin", typeButton);
menu1.dropdown.setSize(109, 32);

menu1.textField.setStyle("textFormat", typeTextFormat);
menu1.move(120, 0);
menu1.prompt = "All Work";
menu1.dataProvider = new DataProvider(workList);


Ok, so I have found out the answer. Well half of it! I now have two Sprites, both the same in shape but called typeButton and dropButton. These are both added to the parent menu1 and menu1.dropdown respectively. I no longer get the disappearing problem. So this works fine... for a bit... but after clicking around for a bit I eventually get Argument Error: 2025 and my limited knowledge comes up against a brick wall...

import fl.data.DataProvider;
import fl.controls.ComboBox;

var typeTextFormat:TextFormat = new TextFormat();
typeTextFormat.color = 0xFFCC00;
typeTextFormat.size = 11;
typeTextFormat.font = "Verdana";

var menu1:ComboBox = new ComboBox();
addChild(menu1);

var typeButton:Sprite = new Sprite();
menu1.addChild(typeButton);
typeButton.graphics.beginFill(0x000000);
typeButton.graphics.drawRect(0, 0, 109, 34);
typeButton.graphics.endFill();
typeButton.alpha = 0.75;
typeButton.filters = [new DropShadowFilter(3,120,0x000000,0.5,0,0,1,1,false,false,false)];

var dropButton:Sprite = new Sprite();
menu1.dropdown.addChild(dropButton);
dropButton.graphics.beginFill(0x000000);
dropButton.graphics.drawRect(0, 0, 109, 34);
dropButton.graphics.endFill();
dropButton.alpha = 0.75;
dropButton.filters = [new DropShadowFilter(3,120,0x000000,0.5,0,0,1,1,false,false,false)];

menu1.setStyle("upSkin", typeButton);
menu1.setStyle("overSkin", typeButton);
menu1.setStyle("downSkin", typeButton);
menu1.setSize(109, 34);

menu1.dropdown.setRendererStyle("upSkin", dropButton);
menu1.dropdown.setRendererStyle("overSkin", dropButton);
menu1.dropdown.setRendererStyle("downSkin", dropButton);
menu1.dropdown.setSize(109, 34);

menu1.textField.setStyle("textFormat", typeTextFormat);
menu1.dropdown.setRendererStyle("textFormat", typeTextFormat);
menu1.move(120, 0);
menu1.prompt = "All Work";
var dp:DataProvider = new DataProvider();
dp.addItem( { label: "All Work", data: "all" } );
dp.addItem( { label: "Work1", data: "w1" } );
dp.addItem( { label: "Work2", data: "w2" } );
dp.addItem( { label: "Work3", data: "w3" } );
menu1.dataProvider = dp;


var dp:DataProvider = new DataProvider();
dp.addItem( { label: "All Work", data: "all" } );
dp.addItem( { label: "Work1", data: "w1" } );
dp.addItem( { label: "Work2", data: "w2" } );
dp.addItem( { label: "Work3", data: "w3" } );

menu1.dataProvider = dp;

[EDIT]
Working code in cs4

import fl.data.DataProvider;
import fl.controls.ComboBox

var typeTextFormat:TextFormat = new TextFormat();
typeTextFormat.color = 0xFFCC00;
typeTextFormat.size = 11;
typeTextFormat.font = "Verdana";


var typeButton:Sprite = new Sprite();
addChild(typeButton);
typeButton.graphics.beginFill(0x000000);
typeButton.graphics.drawRect(0, 0, 109, 32);
typeButton.graphics.endFill();
typeButton.alpha = 0.75;
typeButton.filters = [new GlowFilter(0x000000,0.5,0,12,1,1,false,false)];


var menu1:ComboBox = new ComboBox();
addChild(menu1);

menu1.setStyle("upSkin", typeButton);
menu1.setStyle("overSkin", typeButton);
menu1.setStyle("downSkin", typeButton);
menu1.setSize(109, 32);

menu1.dropdown.setRendererStyle("upSkin", typeButton);
menu1.dropdown.setRendererStyle("overSkin", typeButton);
menu1.dropdown.setRendererStyle("downSkin", typeButton);
menu1.dropdown.setSize(109, 32);

menu1.textField.setStyle("textFormat", typeTextFormat);
menu1.move(120, 0);
menu1.prompt = "All Work";
var dp:DataProvider = new DataProvider();
dp.addItem( { label: "All Work", data: "all" } );
dp.addItem( { label: "Work1", data: "w1" } );
dp.addItem( { label: "Work2", data: "w2" } );
dp.addItem( { label: "Work3", data: "w3" } );
menu1.dataProvider = dp;

[EDIT 2]
Ok, now that I see what issues your are having.
It seems your issue is with the following lines

menu1.dropdown.setRendererStyle("upSkin", typeButton);
menu1.dropdown.setRendererStyle("overSkin", typeButton);
menu1.dropdown.setRendererStyle("downSkin", typeButton);

Apparently, the combobox dropdown is list based and as such uses an item renderer.
So you have to set the skin through the renderer.

comboBox.dropdown.itemRenderer = "someItemRender.as";

I also ran across this site. but, I could not get it to work, although the idea seems to be solid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜