I 开发者_Go百科am creating an Actionscript 3 application in Flash CS4. I created a movie clip called dropDown with it exporting for Actionscript as dropDown. Inside this movie clip i dropped a numericStepper Component. I also have a basic movie clip of a box with text that says Add Dropdown exporting for Actionscript as DropDownBtn. Really basic.
the Add Dropdown button creates an instance of the movieclip via an event listener and callback function.
Once the instance is created I cant seem to access the value of the Numeric Stepper. MY code is as follows:
//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;
}
you have
var newDropDown = new dropDown();
scoped to inside the addDropdown function
You need to move it outside that function to make it have a global scope
//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;
}
Ok I got it.
I had to reference the instance name of the NumericStepper inside the movie clip. Like this.
var numericStepperValue = movieClip.NumericStepperInstance.value;
thanks for your help.
精彩评论