Fork me on GitHub
Not signed in (Sign In)
    • CommentAuthormcav
    • CommentTimeNov 10th 2009 edited
     
    My SWF's root (document class movieclip) is scaled so that I can have some objects resize to the stage and some not.

    DisplayObjectZone presently doesn't calculate proper bounds in that case. I've changed a couple lines in DisplayObjectZone.as which fix the problem. In essence, I use getBounds from the "root" display object ,and then convert those coordinates to renderer coordinates. (Your code used the stage to do that, but didn't work with scaling properly).


    /**
    * The getLocation method returns a random point inside the zone.
    *
    * @return a random point inside the zone.
    */
    public function getLocation() : Point
    {
    var bounds:Rectangle = _displayObject.getBounds( _displayObject.root );
    do
    {
    var x : Number = bounds.left + Math.random( ) * bounds.width;
    var y : Number = bounds.top + Math.random( ) * bounds.height;
    }
    while( !_displayObject.hitTestPoint( x, y, true ) );
    var point:Point = new Point( x, y );
    point = _renderer.globalToLocal( displayObject.root.localToGlobal( point ) );
    return point;
    }



    I should add that without this patch, it gets stuck in the while() loop because hitTestPoint never returns true.
    • CommentAuthorRichard
    • CommentTimeNov 12th 2009
     
    Thank you for finding and fixing the bug.

    I'll check your patch at the weekend and commit it to SVN. Unfortunately, you just missed the 2.1.3 update so it'll be in 2.1.4 when I release that.

    Richard
    • CommentAuthormcav
    • CommentTimeDec 29th 2009
     
    No problem. Let me know if you need more explanation or another test case.
    • CommentAuthormcav
    • CommentTimeMar 9th 2010
     
    [bump]