我正在Flash CS4中创建一个Actionscript 3应用程序。我创建了一个名为dropDown的影片剪辑,并将其作为dropDown导出为Actionscript。在这个影片剪辑中,我删除了一个numericStepper组件。我还有一个带有文本框的基本影片剪辑,其中为Actionscript添加Dropdown导出为DropDownBtn。真的很基本。
“添加下拉”按钮通过事件侦听器和回调函数创建movieclip的实例。
创建实例后,我似乎无法访问数字步进器的值。我的代码如下:
//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;
}
答案 0 :(得分:0)
你有
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;
}
答案 1 :(得分:0)
好的,我明白了。
我必须在影片剪辑中引用NumericStepper的实例名称。像这样。
var numericStepperValue = movieClip.NumericStepperInstance.value;
感谢您的帮助。