Flash中As3的ComboBox获取所选项的值
package{importflash.display.MovieClip;importfl.controls.ComboBox;importflash.display....
package
{
import flash.display.MovieClip;
import fl.controls.ComboBox;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.MouseEvent;
import fl.controls.List;
public class main extends MovieClip
{
var myComboBox:ComboBox=new ComboBox();
public function main()
{
var myComboBox:ComboBox = new ComboBox();
myComboBox.addItem({data:"全部模式",label:"全部模式"});
myComboBox.addItem({data:"竞技模式",label:"竞技模式"});
myComboBox.addItem({data:"挑战模式",label:"挑战模式"});
myComboBox.move(10, 30);
addChild(myComboBox);
var tf:TextFormat= new TextFormat();
tf.color = 0xFFFFFF;
tf.font = "宋体";
tf.size = 12;
//设置下拉框默认字体
myComboBox.textField.setStyle("textFormat",tf);
//设置下拉框List字体;
myComboBox.dropdown.setRendererStyle("textFormat",tf);
//ComboBox的实例名为selectBox,添加侦听;
myComboBox.addEventListener(Event.CHANGE, cbListener);
}
function cbListener(e:Event)
{
trace(myComboBox.selectedItem.data);//选中ComboBox的哪一项就输出哪一项的值
}
}
}
复制代码
提示我出TypeError: Error #1009: 无法访问空对象引用的属性或方法。
at main/cbListener()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::ComboBox/onListChange()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::SelectableList/handleCellRendererClick()
我想要ComboBox获取所选项的值ComboBox获取所选项的值怎么办,求好心人帮忙解答一下,谢谢!!!!最好是源码。 展开
{
import flash.display.MovieClip;
import fl.controls.ComboBox;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.MouseEvent;
import fl.controls.List;
public class main extends MovieClip
{
var myComboBox:ComboBox=new ComboBox();
public function main()
{
var myComboBox:ComboBox = new ComboBox();
myComboBox.addItem({data:"全部模式",label:"全部模式"});
myComboBox.addItem({data:"竞技模式",label:"竞技模式"});
myComboBox.addItem({data:"挑战模式",label:"挑战模式"});
myComboBox.move(10, 30);
addChild(myComboBox);
var tf:TextFormat= new TextFormat();
tf.color = 0xFFFFFF;
tf.font = "宋体";
tf.size = 12;
//设置下拉框默认字体
myComboBox.textField.setStyle("textFormat",tf);
//设置下拉框List字体;
myComboBox.dropdown.setRendererStyle("textFormat",tf);
//ComboBox的实例名为selectBox,添加侦听;
myComboBox.addEventListener(Event.CHANGE, cbListener);
}
function cbListener(e:Event)
{
trace(myComboBox.selectedItem.data);//选中ComboBox的哪一项就输出哪一项的值
}
}
}
复制代码
提示我出TypeError: Error #1009: 无法访问空对象引用的属性或方法。
at main/cbListener()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::ComboBox/onListChange()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::SelectableList/handleCellRendererClick()
我想要ComboBox获取所选项的值ComboBox获取所选项的值怎么办,求好心人帮忙解答一下,谢谢!!!!最好是源码。 展开
2个回答
展开全部
package
{
import flash.display.MovieClip;
import fl.controls.ComboBox;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.MouseEvent;
import fl.controls.List;
public class Main extends MovieClip
{
var myComboBox:ComboBox
public function Main()
{
trace("hello");
var myComboBox:ComboBox = new ComboBox();
myComboBox.addItem({label:"全部模式",data:"全部模式"});
myComboBox.addItem({label:"竞技模式",data:"竞技模式"});
myComboBox.addItem({label:"挑战模式",data:"挑战模式"});
myComboBox.x=myComboBox.y=10;
addChild(myComboBox);
var tf:TextFormat= new TextFormat();
tf.color = 0xFFFFFF;
tf.font = "宋体";
tf.size = 12;
//设置下拉框默认字体
myComboBox.textField.setStyle("textFormat",tf);
//设置下拉框List字体;
myComboBox.dropdown.setRendererStyle("textFormat",tf);
//ComboBox的实例名为selectBox,添加侦听;
myComboBox.addEventListener(Event.CHANGE, cbListener);
}
function cbListener(e:Event)
{
trace(ComboBox(e.target).selectedItem.data);
//trace(myComboBox.selectedItem.data);
}
}
}
试试这个,我在CS5上调过的
{
import flash.display.MovieClip;
import fl.controls.ComboBox;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.MouseEvent;
import fl.controls.List;
public class Main extends MovieClip
{
var myComboBox:ComboBox
public function Main()
{
trace("hello");
var myComboBox:ComboBox = new ComboBox();
myComboBox.addItem({label:"全部模式",data:"全部模式"});
myComboBox.addItem({label:"竞技模式",data:"竞技模式"});
myComboBox.addItem({label:"挑战模式",data:"挑战模式"});
myComboBox.x=myComboBox.y=10;
addChild(myComboBox);
var tf:TextFormat= new TextFormat();
tf.color = 0xFFFFFF;
tf.font = "宋体";
tf.size = 12;
//设置下拉框默认字体
myComboBox.textField.setStyle("textFormat",tf);
//设置下拉框List字体;
myComboBox.dropdown.setRendererStyle("textFormat",tf);
//ComboBox的实例名为selectBox,添加侦听;
myComboBox.addEventListener(Event.CHANGE, cbListener);
}
function cbListener(e:Event)
{
trace(ComboBox(e.target).selectedItem.data);
//trace(myComboBox.selectedItem.data);
}
}
}
试试这个,我在CS5上调过的
展开全部
package
{
import flash.display.MovieClip;
import fl.controls.ComboBox;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.MouseEvent;
import fl.controls.List;
public class Main extends MovieClip
{
var myComboBox:ComboBox
public function Main()
{
trace("hello");
var myComboBox:ComboBox = new ComboBox();
myComboBox.addItem({label:"全部模式",data:"全部模式"});
myComboBox.addItem({label:"竞技模式",data:"竞技模式"});
myComboBox.addItem({label:"挑战模式",data:"挑战模式"});
myComboBox.x=myComboBox.y=10;
addChild(myComboBox);
var tf:TextFormat= new TextFormat();
tf.color = 0xFFFFFF;
tf.font = "宋体";
tf.size = 12;
//设置下拉框默认字体
myComboBox.textField.setStyle("textFormat",tf);
//设置下拉框List字体;
myComboBox.dropdown.setRendererStyle("textFormat",tf);
//ComboBox的实例名为selectBox,添加侦听;
myComboBox.addEventListener(Event.CHANGE, cbListener);
}
function cbListener(e:Event)
{
trace(ComboBox(e.target).selectedItem.data);
//trace(myComboBox.selectedItem.data);
}
}
}
试试这个,我在CS5上调过的
{
import flash.display.MovieClip;
import fl.controls.ComboBox;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.MouseEvent;
import fl.controls.List;
public class Main extends MovieClip
{
var myComboBox:ComboBox
public function Main()
{
trace("hello");
var myComboBox:ComboBox = new ComboBox();
myComboBox.addItem({label:"全部模式",data:"全部模式"});
myComboBox.addItem({label:"竞技模式",data:"竞技模式"});
myComboBox.addItem({label:"挑战模式",data:"挑战模式"});
myComboBox.x=myComboBox.y=10;
addChild(myComboBox);
var tf:TextFormat= new TextFormat();
tf.color = 0xFFFFFF;
tf.font = "宋体";
tf.size = 12;
//设置下拉框默认字体
myComboBox.textField.setStyle("textFormat",tf);
//设置下拉框List字体;
myComboBox.dropdown.setRendererStyle("textFormat",tf);
//ComboBox的实例名为selectBox,添加侦听;
myComboBox.addEventListener(Event.CHANGE, cbListener);
}
function cbListener(e:Event)
{
trace(ComboBox(e.target).selectedItem.data);
//trace(myComboBox.selectedItem.data);
}
}
}
试试这个,我在CS5上调过的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询