开发者

Is listening to the Render event good or bad?

What I am trying to achieve is to extending a component in Flex and add an image to be shown ALWAYS n开发者_运维百科ext to it. (The image cannot be added inside (addElement/addChild) the control)

I have calculated the coordinates of the control and managed to position to the image always next to it without any issues in the Creation_Complete event. But what I noticed was, when the screen is resized and the position of the control is changed, the image still stays in the same location.

So I listened to the Render event and did the coordinate calculation to place the image right next to the control. Now this works perfectly.

But the issue I have is whether listening to the Render event to do the coordinate calculation is bad for performance? Is there a another event that is less frequently fired, to do my job?

Hope it is clear and thanx a lot in advance :)


You are talking about resizing of the screen, then you could also listen to the resize event (off the stage), instead of the render event (on the image).

This should only fire when there is a resizing of the stage.

stage.addEventListener(Event.RESIZE, resizeListener);


If you are extending a component you may try to use the superior Flex components lifecycle, overriding updateDisplayList() method to position the component where you do see fit, taking into consideration the screen size and will the element be visible, etc. Of course you may want to internally tap into resize event with a simple function that will only call invalidateDisplayList(), making sure that no neccessary calls will for reposition will be made. This is a method /the updateDisplayList()/ that is called only once during render stage. Also for adding the new element into your extended component it would be reasonable to override createChildren() to create and add the image. During that phase nothing else is required, since updateDisplayList() will be automaticly called if child is added/removed.

Component Lifecycle Explanation - This one was of a great help for me :")


I ended up listening to Render once as a workaround, but if you set a breakpoint in the Render handler, you will probably noitce that it is called 1000's of times: I would say BAD.

I would suggest a resize event added to the Application tag resize="application_resize(event);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜