Reputation: 935
I want to add a Rect to a Sprite, but failed. A Rect can only be added with addElement, which Sprite has not (only has addChild). What's the alternative?
Upvotes: 0
Views: 124
Reputation: 18193
I somewhat disagree with @Florian Salihovic's answer, on principal. A Sprite
is a low level object that is natively defined in the Flash player. It is significantly more lightweight than any Flex component would ever be. Why not use it in your app if it meets your needs?
You just have to be aware that the Sprite
will not do all of the fancy things that a Flex component does. This limits the uses of it in a Flex app, but by all means, does not preclude it.
Granted, I don't use Sprite
's in Flex that often. I just want to voice that it is OK and there are perfectly good scenarios to use a Sprite
in your Flex app:
Sprite
as a maskSprite
for a child object inside of a Flex componentGraphics
API on a lightweight objectFor your specific scenario, the suggestions already made are good, I will expound on them some more:
Rect
), so it won't be unfamiliar. When you instantiate an FXG object in your Flex app, you type it as a SpriteVisualElement
. So the drawing you make declaratively in FXG can be instantiated as a SpriteVisualElement
and then you have access to it's Graphics
api to do additional drawing on it.Upvotes: 0
Reputation: 3951
No, you actually don't want to use Sprites or MovieClips. The UI layer in Flex is based on UIComponent so the framework expects this class to be used as a base class. Measuring/sizing, positioning etc. are based on the Flex component live cycle which has to be implemented explicitly/implicitly by components to work with the framework.
Everything else is a fight against the framework and loosing a lot of benefits.
Upvotes: 1