alexvoz / as3isolib

Automatically exported from code.google.com/p/as3isolib
0 stars 0 forks source link

IsoScene.addChild throws a RangeError #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Set up an IsoScene which is rendered through an IsoView with the
DefaultViewRenderer.
2. Populate the scene with several Objects, some of which are outside the view.
3. Add a Child to the scene with IsoScene.addChild - bam:

RangeError: Error #2006: Der angegebene Index liegt außerhalb des
zulässigen Bereichs.
    at flash.display::DisplayObjectContainer/addChildAt()
    at
as3isolib.core::IsoContainer/addChildAt()[D:\projects\AnyrayFlex\src\as3isolib\c
ore\IsoContainer.as:119]
    at
as3isolib.display.scene::IsoScene/addChildAt()[D:\projects\AnyrayFlex\src\as3iso
lib\display\scene\IsoScene.as:146]
    at
as3isolib.data::Node/addChild()[D:\projects\AnyrayFlex\src\as3isolib\data\Node.a
s:225]
    at
xi::CityView/mouseMoveHandler()[D:\projects\AnyrayFlex\src\xi\CityView.as:175]

My diagnosis:

The IsoContainer.addChildAt function tries to call the AS3 addChildAt
function of the IsoScene's mainContainer (a Sprite), passing an index which
corresponds to the total number of this IsoContainer's children.
However, due to the ViewRenderer, the number of children which are actually
displayed can be smaller.

My Solution for now is a small modification in IsoContainer.as:

override public function addChildAt (child:INode, index:uint):void
{
    if (child is IIsoContainer)
    {
        super.addChildAt(child, index);

        if (IIsoContainer(child).includeInLayout)
        {
            displayListChildrenArray.push(child);
            if (index > mainContainer.numChildren) {
                trace("index too large: ", index, "should be <",
mainContainer.numChildren);
                index = mainContainer.numChildren;
            }
            mainContainer.addChildAt(IIsoContainer(child).container, index);
        }
    }

    else
        throw new Error("parameter child does not implement IContainer.");
}

Original issue reported on code.google.com by marco.haag@gmail.com on 4 Jan 2009 at 3:01

GoogleCodeExporter commented 9 years ago

Original comment by jwopitz on 6 Jan 2009 at 3:47

GoogleCodeExporter commented 9 years ago
I added your fix to the IsoContainer code.  This will be reflected in the beta
release SWC (when available) and in the SVN trunk (currently).

Original comment by jwopitz on 6 Jan 2009 at 4:39