Re: [flexcoders] event listeners on Sprites - performance problem
Are all 10-15 markers visible at one time? If not, you might want to consider the 'recycle' method that is employed with item renderers. Either that... or have a single MEGA WONKA sprite where each marker is drawn at the appropriate location. Rick Winscot On Wed, Jul 23, 2008 at 12:42 PM, Alex Harui [EMAIL PROTECTED] wrote: 10 to 15 shouldn't be a problem. Make sure it is only that many (and you didn't create more and stack them on top of the others). Are you saying the addEventLIstener calls are affecting the cpu load? From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of ibo Sent: Wednesday, July 23, 2008 8:05 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] event listeners on Sprites - performance problem MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=0-617774704-1216825475=:34053 --0-617774704-1216825475=:34053 Content-Type: text/plain; charset=us-ascii I created a component what I call bookmark bar where there are markers that you can click to jump/scroll to a particular portion of a list (given the index). Similar to Eclipse/Flexbuilder when you have errors and there are markers on the right side pane that lets you jump to the erroneous line. I am using this for a datagrid using Canvas as parent component. var uiComponent:UIComponent = new UIComponent(); addChild(uiComponent); for (var i:int=0; i_dataProvider.length; i++) { var bm:Bookmark = _dataProvider[i] as Bookmark; sprite = new MySprite(); // extends Sprite. Creates an instance Sprite for each marker sprite.graphics.lineStyle(3, bm.color, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE); sprite.graphics.moveTo(x, y); sprite.graphics.lineTo(x + xOffset, y); ... sprite.addEventListener(MouseEvent.CLICK, scrollToLine); sprite.buttonMode = true; ... uiComponent.addChild(sprite); } It works as expected but I noticed it is heavy on CPU and affects the responsiveness of the UI. CPU spikes at 55% to 60% even if I only have a few markers (10 to 15). The lag is very noticeable because just hovering the mouse pointer over the list, the item highlighter, delay in rendering the display is very evident. It doesnt happen on my app when I turn it off. Am I doing this right? any workaround? Regards, Stephen --0-617774704-1216825475=:34053 Content-Type: text/html; charset=us-ascii htmlheadstyle type=text/css!-- DIV {margin:0px;} --/style/headbodydiv style=font-family:times new roman, new york, times, serif;font-size:12ptdivI created a component what I call bookmark bar where there are markers that you can clickbrto jump/scroll to a particular portion of a list (given the index). Similar to Eclipse/Flexbuilder when you havebrerrors and there are markers on the right side pane that lets you jump to the erroneous line. I am using brthis for a datagrid using Canvas as parent component.brbrnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; var uiComponent:UIComponent = new UIComponent();nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;! nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; addChild(uiComponent);brbrnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; for (var i:int=0; ilt;_dataProvider.length; i++) {brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; var bm:Bookmark = _dataProvider[i] as Bookmark;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; sprite = new MySprite();nbsp;nbsp; // extends Sprite. Creates an instance Sprite f! or each markerbrnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.graphics.lineStyle(3, bm.color, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE);nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.graphics.moveTo(x,nbsp; y);brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.graphics.lineTo(x + xOffset, y);brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; ... nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.addEventListener(MouseEvent.CLICK, scrollToLine);br! gt;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.buttonMode = true;brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; ...brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; uiComponent.addChild(sprite);nbsp;nbsp;nbsp;
RE: [flexcoders] event listeners on Sprites - performance problem
10 to 15 shouldn't be a problem. Make sure it is only that many (and you didn't create more and stack them on top of the others). Are you saying the addEventLIstener calls are affecting the cpu load? From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of ibo Sent: Wednesday, July 23, 2008 8:05 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] event listeners on Sprites - performance problem MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=0-617774704-1216825475=:34053 --0-617774704-1216825475=:34053 Content-Type: text/plain; charset=us-ascii I created a component what I call bookmark bar where there are markers that you can click to jump/scroll to a particular portion of a list (given the index). Similar to Eclipse/Flexbuilder when you have errors and there are markers on the right side pane that lets you jump to the erroneous line. I am using this for a datagrid using Canvas as parent component. var uiComponent:UIComponent = new UIComponent(); addChild(uiComponent); for (var i:int=0; i_dataProvider.length; i++) { var bm:Bookmark = _dataProvider[i] as Bookmark; sprite = new MySprite(); // extends Sprite. Creates an instance Sprite for each marker sprite.graphics.lineStyle(3, bm.color, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE); sprite.graphics.moveTo(x, y); sprite.graphics.lineTo(x + xOffset, y); ... sprite.addEventListener(MouseEvent.CLICK, scrollToLine); sprite.buttonMode = true; ... uiComponent.addChild(sprite); } It works as expected but I noticed it is heavy on CPU and affects the responsiveness of the UI. CPU spikes at 55% to 60% even if I only have a few markers (10 to 15). The lag is very noticeable because just hovering the mouse pointer over the list, the item highlighter, delay in rendering the display is very evident. It doesnt happen on my app when I turn it off. Am I doing this right? any workaround? Regards, Stephen --0-617774704-1216825475=:34053 Content-Type: text/html; charset=us-ascii htmlheadstyle type=text/css!-- DIV {margin:0px;} --/style/headbodydiv style=font-family:times new roman, new york, times, serif;font-size:12ptdivI created a component what I call bookmark bar where there are markers that you can clickbrto jump/scroll to a particular portion of a list (given the index). Similar to Eclipse/Flexbuilder when you havebrerrors and there are markers on the right side pane that lets you jump to the erroneous line. I am using brthis for a datagrid using Canvas as parent component.brbrnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; var uiComponent:UIComponent = new UIComponent();nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;! nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; addChild(uiComponent);brbrnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; for (var i:int=0; ilt;_dataProvider.length; i++) {brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; var bm:Bookmark = _dataProvider[i] as Bookmark;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbs p;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; sprite = new MySprite();nbsp;nbsp; // extends Sprite. Creates an instance Sprite f! or each markerbrnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.graphics.lineStyle(3, bm.color, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE);nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.graphics.moveTo(x,nbsp; y);brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.graphics.lineTo(x + xOffset, y);brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; ... nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.addEventListener(MouseEvent.CLICK, scrollToLine);br! gt;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; sprite.buttonMode = true;brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; ...brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; uiComponent.addChild(sprite);nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; brnbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp; }brbrIt works as expected but I noticed it is heavy on CPU and affects the responsiveness of thebrUI. CPU spikes at 55% to 60% even if I only have a few markers (10 to 15).brThe lag is very noticeable because just hovering the mouse pointer over the list,brthe item highlighter, delay
RE: [flexcoders] Event Listeners
Hi Michael, I imagine its because your event listener is an anonymous function, so the removeEventListener must be passed a reference to the same function. Try this (untested) myHandler : Function = Delegate.create( this, handleEvent ); pane.addEventListener("contentCreated",myHandler ); ... pane.removeEventListener("contentCreated",myHandler ); myHandler may have to be stored asan instance variable if (as I suspect) the add and remove are in different scope. Please let us know if that works. Ali -- Alistair McLeodDevelopmentDirector iteration::two[EMAIL PROTECTED] Office: +44 (0)131 338 6108 This e-mail and any associated attachments transmitted with it may contain confidential information and must not be copied, or disclosed, or used by anyone other than the intended recipient(s). If you are not the intended recipient(s) please destroy this e-mail, and any copies of it, immediately.Please also note that while software systems have been used to try to ensure that this e-mail has been swept for viruses, iteration::two do not accept responsibility for any damage or loss caused in respect of any viruses transmitted by the e-mail. Please ensure your own checks are carried out before any attachments are opened. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Michael HerronSent: 19 May 2005 12:18To: flexcoders@yahoogroups.comSubject: [flexcoders] Event Listeners All, I am having a problem with removing event listeners on a panel. I am adding the event listener like so: pane.addEventListener("contentCreated", Delegate.create(this, handleEvent) ); But trying to remove the event listener using removeEventListener does not seem to work. I have tried several variants: pane.removeEventListener("contentCreated", Delegate.create(this, handleEvent) ); pane.removeEventListener("contentCreated", Delegate.create(this) ); pane.removeEventListener("contentCreated", this.handleEvent ); pane.removeEventListener("contentCreated", this ); and none seem to work. Ive been struggling with this for a good few hours and its driving me crazy, any help would be appreciated. Ta Mike Herron Yahoo! Groups Links To visit your group on the web, go to:http://groups.yahoo.com/group/flexcoders/ To unsubscribe from this group, send an email to:[EMAIL PROTECTED] Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
RE: [flexcoders] Event Listeners
Hi Alistair, That worked perfectly, cheers! From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Alistair McLeod Sent: 19 May 2005 12:31 To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Event Listeners Hi Michael, I imagine its because your event listener is an anonymous function, so the removeEventListener must be passed a reference to the same function. Try this (untested) myHandler : Function = Delegate.create( this, handleEvent ); pane.addEventListener(contentCreated,myHandler ); ... pane.removeEventListener(contentCreated,myHandler ); myHandler may have to be stored asan instance variable if (as I suspect) the add and remove are in different scope. Please let us know if that works. Ali -- Alistair McLeod DevelopmentDirector iteration::two [EMAIL PROTECTED] Office: +44 (0)131 338 6108 This e-mail and any associated attachments transmitted with it may contain confidential information and must not be copied, or disclosed, or used by anyone other than the intended recipient(s). If you are not the intended recipient(s) please destroy this e-mail, and any copies of it, immediately. Please also note that while software systems have been used to try to ensure that this e-mail has been swept for viruses, iteration::two do not accept responsibility for any damage or loss caused in respect of any viruses transmitted by the e-mail. Please ensure your own checks are carried out before any attachments are opened. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Michael Herron Sent: 19 May 2005 12:18 To: flexcoders@yahoogroups.com Subject: [flexcoders] Event Listeners All, I am having a problem with removing event listeners on a panel. I am adding the event listener like so: pane.addEventListener(contentCreated, Delegate.create(this, handleEvent) ); But trying to remove the event listener using removeEventListener does not seem to work. I have tried several variants: pane.removeEventListener(contentCreated, Delegate.create(this, handleEvent) ); pane.removeEventListener(contentCreated, Delegate.create(this) ); pane.removeEventListener(contentCreated, this.handleEvent ); pane.removeEventListener(contentCreated, this ); and none seem to work. Ive been struggling with this for a good few hours and its driving me crazy, any help would be appreciated. Ta Mike Herron Yahoo! Groups Links To visit your group on the web, go to:http://groups.yahoo.com/group/flexcoders/ To unsubscribe from this group, send an email to:[EMAIL PROTECTED] Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.