我正在创建一个动作脚本3应用程序在闪光CS4。我创建了一个名为dropDown的影片剪辑,并将其导出为dropDown格式。在这个影片剪辑中,我放入了一个numericStepper组件。我还有一个带有文本框的基本影片剪辑,上面写着Add Dropdown exporting for Actionscript as DropDownBtn。非常基础。
添加下拉按钮通过事件侦听器和回调函数创建电影剪辑的实例。
一旦创建了实例,我似乎就不能访问数值步长的值了。我的代码如下:
//create the load dropdown button
var newButton = new DropDownBtn();
//position the button
newButton.x = 20;
newButton.y = 20;
//and add it to the stage
addChild(newButton);
//add the event listener to the button
newButton.addEventListener(MouseEvent.MOUSE_DOWN, addDropdown);
function addDropdown(e:MouseEvent):void{
//create and instance of the drop down
var newDropDown = new dropDown();
//move it over beside the add dropdown button
newDropDown.x = newButton.width+40;
newDropDown.y = 20;
//add the instance of the newDropDown to the display stack
addChild(newDropDown);
//add the event listener to the dropdown
newDropDown.addEventListener(Event.CHANGE, useDropDownValue);
}
function useDropDownValue(e:Event):void{
//this is where I need to utilize the value of the Numeric Stepper
//I thought it would be accessed as follows but it doesn't seem to work
//I added a trace to make sure this function is being executed and that works
//when i comment out my attempt at using the Numeric Stepper Value
trace("useDropDownValue Function Accessed");
var dropDownValue = newDropdown.value;
}发布于 2011-04-27 01:52:58
好的,我知道了。
我必须在影片剪辑中引用NumericStepper的实例名称。就像这样。
var numericStepperValue = movieClip.NumericStepperInstance.value;谢谢你的帮助。
发布于 2011-04-26 10:43:23
你有
var newDropDown = new dropDown();作用域为addDropdown函数内部
您需要将其移出该函数,以使其具有全局作用域
//create the load dropdown button
var newButton = new DropDownBtn();
//position the button
newButton.x = 20;
newButton.y = 20;
//and add it to the stage
addChild(newButton);
//add the event listener to the button
newButton.addEventListener(MouseEvent.MOUSE_DOWN, addDropdown);
// GLOBAL SCOPE HERE
//create and instance of the drop down
var newDropDown = new dropDown();
function addDropdown(e:MouseEvent):void{
//move it over beside the add dropdown button
newDropDown.x = newButton.width+40;
newDropDown.y = 20;
//add the instance of the newDropDown to the display stack
addChild(newDropDown);
//add the event listener to the dropdown
newDropDown.addEventListener(Event.CHANGE, useDropDownValue);
}
function useDropDownValue(e:Event):void{
//this is where I need to utilize the value of the Numeric Stepper
//I thought it would be accessed as follows but it doesn't seem to work
//I added a trace to make sure this function is being executed and that works
//when i comment out my attempt at using the Numeric Stepper Value
trace("useDropDownValue Function Accessed");
var dropDownValue = newDropdown.value;
}https://stackoverflow.com/questions/5785218
复制相似问题