簡體   English   中英

AS3 NumericStepper組件

[英]AS3 NumericStepper Component

我正在Flash CS4中創建一個Actionscript 3應用程序。 我創建了一個名為dropDown的影片剪輯,並將其導出為ActionScript作為dropDown。 在此影片剪輯中,我放置了一個numericStepper組件。 我也有一個文本框,上面寫着添加下拉為ActionScript導出為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;
    }

你有

 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;
    }

好,我知道了。

我必須在影片剪輯中引用NumericStepper的實例名稱。 像這樣。

var numericStepperValue = movieClip.NumericStepperInstance.value;

謝謝你的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM