Hi,

It's not possible to move your "cp" variable between containers like
that. When you call addChild the second time. "cp" is still in the
first containers child list.

As Flex updates the display, it runs over the arrays of children on
the component you remove from and thinks cp is still there, except it
isn't. Hence the RangeError (array index out of bounds).

Every child has a "parent" attribute that points to it's parent. At
any point during runtime, there can only be one reference here, so you
have to cleanly remove "cp" from it's old container *before* adding it
to the new one.

Really read this carefully:
http://livedocs.macromedia.com/flex/2/docs/00001850.html

Technically, I think Flex should do the clean remove for you
(according to the document above anyway). I have a sneaky feeling
though, that this exception throw is partially to alert the developer
to potential berk-traps in code.

Best of luck,
Ciarán

On 1/10/07, Pavel Zabelin <[EMAIL PROTECTED]> wrote:
>
>    Hi all. I tried to do that:
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"; layout="absolute" 
> currentState="partview" width="100%" height="100%">
> <mx:Script>
> <![CDATA[
> private var cp:Panel
> private function onCopyClick(event:MouseEvent):void
> {
> cp=pnl;
> application.setCurrentState('fullview')
> fullc.addChild(cp);
> }
> private function onCopyClick2(event:MouseEvent):void
> {
> trace(playout+"|"+cp)
> playout.addChild(cp);
> if (fullc.getChildren().length>0)
> {
> fullc.removeAllChildren();
> }
> application.setCurrentState('partview')
> }
> ]]>
> </mx:Script>
> <mx:states>
> <mx:State name="partview">
> <mx:AddChild position="lastChild">
> <mx:VBox id="playout" x="32" y="88" height="351" width="287">
> <mx:Panel id="pnl" width="100%" height="100%" layout="absolute">
> </mx:Panel>
> </mx:VBox>
> </mx:AddChild>
> </mx:State>
> <mx:State name="fullview">
> <mx:AddChild position="lastChild">
> <mx:VBox id="fullc" x="0" y="58" width="100%" height="100%">
> </mx:VBox>
> </mx:AddChild>
>  </mx:State>
> </mx:states>
> <mx:ApplicationControlBar x="0" y="0" width="100%" height="50">
> <mx:Button label="Button1" click="onCopyClick(event)"/>
> <mx:Button label="Button2" click="onCopyClick2(event)"/>
> </mx:ApplicationControlBar>
> </mx:Application>
>
> but I got error with RangeError: Error #2006: The supplied index is out of 
> bounds. What the reason?
>
>   

Reply via email to