AS3 NumericStepper 组件

发布于 2024-11-03 11:06:43 字数 1589 浏览 1 评论 0原文

我正在 Flash CS4 中创建 Actionscript 3 应用程序。我创建了一个名为 dropDown 的影片剪辑,并将 Actionscript 导出为 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;
    }

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

憧憬巴黎街头的黎明 2024-11-10 11:06:43

您已将

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

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;
    }
当爱已成负担 2024-11-10 11:06:43

好的,我明白了。

我必须在影片剪辑中引用 NumericStepper 的实例名称。像这样。

var numericStepperValue = movieClip.NumericStepperInstance.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文