views:

18

answers:

1

how can i retrieve the set graphics properties of a sprite? for example, in the code below, i'd like to get the color of the sprite, also it's rounded corners setting and other graphics attributes.

var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xFF0000, 0.75);
sp.graphics.drawRoundRect(0, 0, 300, 50, 10, 10);
sp.graphics.endFill();

addChild(sp);
trace(sp.graphics.color);  //pseudo trace - this doesn't work
+1  A: 

I am almost certain this is not possible. However, there are certainly other ways to do this. What about having a valueObject for each property that stores the values used. Then you could have a GraphicalDisplayObject that you either inherit from or use via composition. For instance:

package {
    class FillVO extends Object {
        public var fill_color:Number = 0xFF0000;
        public var fill_opacity:Number = 0.75;
    }
}

package {
    import FillVO;
    class GraphicalDisplayObject extends Sprite {
        public var fill_vo:FillVO;
        public function beginFill($vo:FillVO) {
            graphics.beginFill($vo.fill_color, $vo.fill_opacity);
        }
        ...
    }
}

package {
    import GraphicalDisplayObject;
    class ObjectWithGraphicalProperties extends Sprite {
        public var gfx:GraphicalDisplayObject;
        public function ObjectWithGraphicalProperties() {
            gfx = new GraphicalDisplayObject();
            addChild(gfx);
        }
        public function beginFill($color:Number, $opactity:Number) {
            var fill_vo:FillVO = new FillVO();
            fill_vo.fill_color = $color;
            fill_vo.fill_opacity = $opacity;
            gfx.beginFill(fill_vo);
        }
        ...
    }
}

Then to use it...

var obj:ObjectWithGraphicalProperties = new ObjectWithGraphicalProperties();
addChild(obj);
obj.beginFill(0xffff00, .2);
...
...
trace(obj.gfx.fill_vo.fill_color);

This is obviously via composition, and you would need to write the additional proxied methods and corresponding valueObjects... but it should work.

sberry2A
interesting workaround. thanks :)
TheDarkInI1978
TandemAdam