Flex: Render an unrealized UIComponent to BitmapData?

后端 未结 4 1450
没有蜡笔的小新
没有蜡笔的小新 2020-12-15 12:36

What is the best way to render to a UIComponent which hasn\'t been added to the stage? (I\'m using UIComponents as renderers for objects, and want to render ne

4条回答
  •  半阙折子戏
    2020-12-15 13:37

    So much of a UIComponent's layout can be tied to it's context. This is especially true for a lot of its derivatives (e.g. HBox) since the fluidity of the layout is tied to it's parent's size and the number of siblings sharing its parents space.

    Additionally Flex can be a real pain to get to visually update. Often critical render functions aren't done synchronously ... there are callLater, callLater2 and other hacky approaches that make dealing with the auto-magical layout properties of UIComponents a major headache. Not even calling validateNow or updateDisplayList can guarantee that the layout will be correct on the current frame (instead of a few frames in the future).

    I suggest the best thing you can do is not use a UIComponent and try and use a Sprite or other.

    Your approach to attach it but make it invisible (alpha = 0, mouseEnabled = false, mouseChildren = false) is decent. You should listen for the FlexEvent.CREATION_COMPLETE callback before you are certain it is properly laid out. Then you can bitmapData.draw it and then remove it from the stage. If you must use UIComponents then I know of no better way.

提交回复
热议问题