在AS3中编辑ComboBox

时间:2011-05-16 16:24:05

标签: flash actionscript-3 actionscript combobox

我在编辑AS3中的ComboBox时遇到问题。谁能告诉我为什么我的ComboBox消失了?感谢所有提前帮助。


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" },
        { 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);

2 个答案:

答案 0 :(得分:1)

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;

[编辑]
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;

[编辑2]
好的,现在我看到你遇到了什么问题 看来你的问题是以下几行

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

显然,组合框下拉列表是基于列表的,因此使用项目渲染器 所以你必须通过渲染器设置皮肤。

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

我也碰到了这个site.但是,我无法让它发挥作用,尽管这个想法看起来很稳固。

答案 1 :(得分:1)

好的,所以我找到了答案。好一半吧!我现在有两个精灵,形状相同但称为typeButton和dropButton。这些都分别添加到父menu1和menu1.dropdown。我不再得到消失的问题。所以这很好......有点......但是点击一下之后我终于得到了Argument Error:2025并且我的有限知识出现在砖墙上......

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;