错误#2006:提供的索引超出范围,在 Flex 中

发布于 2024-09-03 00:21:47 字数 5233 浏览 1 评论 0原文

我已经为警报框创建了一个组件,并且在主应用程序中使用它,

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"
    backgroundColor="#000000" backgroundAlpha="0.75"
    addedEffect="Fade" hideEffect="Fade"
    horizontalAlign="center" verticalAlign="middle"
    creationComplete="creationCompleteHandler()">
    
    <mx:Style>    
        .myButton {
            overSkin:Embed("folder/over.png");
            upSkin:Embed(source="folder/up.png");
            downSkin:Embed(source="folder/down.png");
        }
    </mx:Style>
    
    <mx:Script>
        <![CDATA[
            import mx.core.Application;
            import mx.managers.PopUpManager;
            import mx.controls.Button;
            
            [Bindable] public var resultHandler:Function;
            
            public function creationCompleteHandler():void {
                initializeButtons();
                this.setFocus();
                Application.application.isAlertShowing = true;
            }
            
            public function initializeButtons():void {
                buttonsContainer.removeAllChildren();
                
                for( var i:int = 0; i < buttonsCount; i++ ) {
                    var button:Button = new Button;
                    button.label = buttonsLabels[i];
                    button.addEventListener(MouseEvent.CLICK, buttonClickHandler);
                    button.styleName = "myButton";
                    
                    buttonsContainer.addChild(button);
                    
                }
                
                Button( buttonsContainer.getChildAt(0) ).setFocus();
            }
            
            private function buttonClickHandler(event:MouseEvent):void {
                selectedButton = Button(event.currentTarget).label;
                
                try {
                    resultHandler.call();
                    this.parent.removeChild(this);
                    Application.application.isAlertShowing = false;
                }
                finally {
                    ;
                }
            }
            
            public function enableLargeMode():void {
                canvas.setStyle("backgroundImage", null);
                canvas.setStyle("backgroundColor", 0xffffff);
                canvas.setStyle("borderColor", 0x3b73b9);
                canvas.setStyle("borderStyle", "solid");
                canvas.setStyle("borderThickness", 4);
                
                titleLabel.setStyle("color", 0x3b73b9);
            }
            
        ]]>
    </mx:Script>
    
    <mx:Number id="buttonsCount">2</mx:Number>
    
    <mx:Array id="buttonsLabels">
        <mx:String>OK</mx:String>
        <mx:String>Yes</mx:String>
        <mx:String>No</mx:String>
    </mx:Array>
    
    <mx:String id="selectedButton"/>
    
    <mx:String id="title"/>
    <mx:String id="text"/>
    
    <mx:Canvas id="canvas" 
        width="268" height="135" backgroundImage="@Embed('AdvancedAlertAssets/alert-box.png')">
        
        <mx:Label id="titleLabel" x="18" y="6"
             color="#ffffff" fontWeight="bold" fontSize="16" fontFamily="GE Inspira" 
             text="{title}"/>
        
        <mx:Text id="textText" left="18" top="36" right="18" height="100%"
            fontFamily="GE Inspira" fontSize="12"
            htmlText="{text}"/>
        
        <mx:HBox id="buttonsContainer" 
            bottom="18" left="0" right="0" horizontalAlign="center">
            
        </mx:HBox>
        
    </mx:Canvas>
    
</mx:VBox>

现在我在这样的应用程序中使用

var advancedAlert:AdvancedAlert = new AdvancedAlert;
            this.addChild(advancedAlert);
            advancedAlert.title = "Title";
            advancedAlert.text = "text";
            advancedAlert.buttonsCount = 2;
            advancedAlert.resultHandler = myAlertHideHandler;
            advancedAlert.initializeButtons();
            advancedAlert.buttonsLabels[0] = "Yes";
            advancedAlert.buttonsLabels[1] = "No";
            
            function myAlertHideHandler( ):void {
                if( advancedAlert.selectedButton == 'Yes' ) {
                     var myAlerta:AdvancedAlert = new AdvancedAlert();
          **this.addChild(myAlerta);**
          myAlerta.title = "Information";
          myAlerta.text = "Unable to connect to the server";            
          myAlerta.buttonsCount = 1;
          myAlerta.resultHandler = alertListnerFirst;           
          myAlerta.initializeButtons();
                }
            }

它显示错误,就像

RangeError: Error #2006: The supplied index is out of bounds.
    at flash.display::DisplayObjectContainer/addChildAt()
    at mx.core::Container/addChildAt()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\Container.as:2206]
    at mx.core::Container/addChild()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\Container.as:2140]
    at main/checkInternetConnection()

我无法理解该错误一样,我该如何解决它?

I have created a component for alert box and I am using it in main application,

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"
    backgroundColor="#000000" backgroundAlpha="0.75"
    addedEffect="Fade" hideEffect="Fade"
    horizontalAlign="center" verticalAlign="middle"
    creationComplete="creationCompleteHandler()">
    
    <mx:Style>    
        .myButton {
            overSkin:Embed("folder/over.png");
            upSkin:Embed(source="folder/up.png");
            downSkin:Embed(source="folder/down.png");
        }
    </mx:Style>
    
    <mx:Script>
        <![CDATA[
            import mx.core.Application;
            import mx.managers.PopUpManager;
            import mx.controls.Button;
            
            [Bindable] public var resultHandler:Function;
            
            public function creationCompleteHandler():void {
                initializeButtons();
                this.setFocus();
                Application.application.isAlertShowing = true;
            }
            
            public function initializeButtons():void {
                buttonsContainer.removeAllChildren();
                
                for( var i:int = 0; i < buttonsCount; i++ ) {
                    var button:Button = new Button;
                    button.label = buttonsLabels[i];
                    button.addEventListener(MouseEvent.CLICK, buttonClickHandler);
                    button.styleName = "myButton";
                    
                    buttonsContainer.addChild(button);
                    
                }
                
                Button( buttonsContainer.getChildAt(0) ).setFocus();
            }
            
            private function buttonClickHandler(event:MouseEvent):void {
                selectedButton = Button(event.currentTarget).label;
                
                try {
                    resultHandler.call();
                    this.parent.removeChild(this);
                    Application.application.isAlertShowing = false;
                }
                finally {
                    ;
                }
            }
            
            public function enableLargeMode():void {
                canvas.setStyle("backgroundImage", null);
                canvas.setStyle("backgroundColor", 0xffffff);
                canvas.setStyle("borderColor", 0x3b73b9);
                canvas.setStyle("borderStyle", "solid");
                canvas.setStyle("borderThickness", 4);
                
                titleLabel.setStyle("color", 0x3b73b9);
            }
            
        ]]>
    </mx:Script>
    
    <mx:Number id="buttonsCount">2</mx:Number>
    
    <mx:Array id="buttonsLabels">
        <mx:String>OK</mx:String>
        <mx:String>Yes</mx:String>
        <mx:String>No</mx:String>
    </mx:Array>
    
    <mx:String id="selectedButton"/>
    
    <mx:String id="title"/>
    <mx:String id="text"/>
    
    <mx:Canvas id="canvas" 
        width="268" height="135" backgroundImage="@Embed('AdvancedAlertAssets/alert-box.png')">
        
        <mx:Label id="titleLabel" x="18" y="6"
             color="#ffffff" fontWeight="bold" fontSize="16" fontFamily="GE Inspira" 
             text="{title}"/>
        
        <mx:Text id="textText" left="18" top="36" right="18" height="100%"
            fontFamily="GE Inspira" fontSize="12"
            htmlText="{text}"/>
        
        <mx:HBox id="buttonsContainer" 
            bottom="18" left="0" right="0" horizontalAlign="center">
            
        </mx:HBox>
        
    </mx:Canvas>
    
</mx:VBox>

Now I am using in application like this

var advancedAlert:AdvancedAlert = new AdvancedAlert;
            this.addChild(advancedAlert);
            advancedAlert.title = "Title";
            advancedAlert.text = "text";
            advancedAlert.buttonsCount = 2;
            advancedAlert.resultHandler = myAlertHideHandler;
            advancedAlert.initializeButtons();
            advancedAlert.buttonsLabels[0] = "Yes";
            advancedAlert.buttonsLabels[1] = "No";
            
            function myAlertHideHandler( ):void {
                if( advancedAlert.selectedButton == 'Yes' ) {
                     var myAlerta:AdvancedAlert = new AdvancedAlert();
          **this.addChild(myAlerta);**
          myAlerta.title = "Information";
          myAlerta.text = "Unable to connect to the server";            
          myAlerta.buttonsCount = 1;
          myAlerta.resultHandler = alertListnerFirst;           
          myAlerta.initializeButtons();
                }
            }

It is showing error like

RangeError: Error #2006: The supplied index is out of bounds.
    at flash.display::DisplayObjectContainer/addChildAt()
    at mx.core::Container/addChildAt()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\Container.as:2206]
    at mx.core::Container/addChild()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\Container.as:2140]
    at main/checkInternetConnection()

I am unable to understood the error how can I resolve it?

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

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

发布评论

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

评论(1

动听の歌 2024-09-10 00:21:47

您必须先对当前父级调用 removeChild(),然后再调用 `addChild() 将其附加到新父级。

function myAlertHideHandler( ):void {
    button.removeChild();                
    if( advancedAlert.selectedButton == 'Yes' ) {
         var myAlerta:AdvancedAlert = new AdvancedAlert();
         **this.addChild(myAlerta);**
         myAlerta.title = "Information";
         myAlerta.text = "Unable to connect to the server";            
         myAlerta.buttonsCount = 1;
         myAlerta.resultHandler = alertListnerFirst;           
         myAlerta.initializeButtons();
    }
}

You have to call removeChild() on the current parent before calling `addChild() to attach it to the new parent.

function myAlertHideHandler( ):void {
    button.removeChild();                
    if( advancedAlert.selectedButton == 'Yes' ) {
         var myAlerta:AdvancedAlert = new AdvancedAlert();
         **this.addChild(myAlerta);**
         myAlerta.title = "Information";
         myAlerta.text = "Unable to connect to the server";            
         myAlerta.buttonsCount = 1;
         myAlerta.resultHandler = alertListnerFirst;           
         myAlerta.initializeButtons();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文