Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-23-2008, 05:35 PM   #1
SirDuke
Geek Apprentice
 
SirDuke's Avatar
 
Join Date: Jun 2007
Location: Greece
Posts: 148
Red face really weird stuff (Yahoo ASTRA Tree - CellRenderer)

I wanted to change the color of the rolled-over node on the tree component so i used:
ActionScript Code:
mainMenu.myTree.addEventListener(ListEvent.ITEM_CLICK, MenuClickHandler); mainMenu.myTree.addEventListener(ListEvent.ITEM_ROLL_OVER, MenuRollOverHandler); mainMenu.myTree.addEventListener(ListEvent.ITEM_ROLL_OUT, MenuRollOutHandler); function MenuRollOverHandler(e:ListEvent){         var cr:TreeCellRenderer = mainMenu.myTree.itemToCellRenderer(e.item) as TreeCellRenderer;         var tf:TextFormat = cr.getStyle("textFormat") as TextFormat;         tf.color = _menuOverColor; //_menuOverColor = "0x000000" } function MenuRollOutHandler(e:ListEvent){         var cr:TreeCellRenderer = mainMenu.myTree.itemToCellRenderer(e.item) as TreeCellRenderer;         var tf:TextFormat = cr.getStyle("textFormat") as TextFormat;         tf.color = _menuColor; //_menuColor = "0x888888" }
And it works fine!

Now i want to change the color of an item when CLICKED so i use:
ActionScript Code:
function MenuClickHandler(e:ListEvent):void {         var cr:TreeCellRenderer = mainMenu.myTree.itemToCellRenderer(e.item) as TreeCellRenderer;         var tf:TextFormat = cr.getStyle("textFormat") as TextFormat;         tf.color = _menuOverColor; }

But this just won't work!
I trace "tf.color" in each of those function. The first two return some number (like 8764948) but the last one (click handler) returns always zero (0)...

I check and see that in both cases i get the same textFormat Object! But in the click event handler i just can't change it...

Can anyone see why this could be caused?

Thanks
SirDuke is offline   Reply With Quote
Old 04-24-2008, 10:28 PM   #2
allenrabinovich
Omniheurist
 
Join Date: Mar 2008
Posts: 35
Default Odd indeed

This is very odd indeed; I am not sure why the behavior differs among the three event listeners. Somehow, it appears, that in the item_click listener, a copy of the TextFormat object is created, rather than a direct pointer.

While I investigate further, there's an easy workaround. After assigning the needed color value to the tf object, call:

cr.setStyle("textFormat", tf);

That will ensure that tf is copied to the textFormat style of the renderer.

Let me know how this goes.
allenrabinovich is offline   Reply With Quote
Old 04-25-2008, 09:49 AM   #3
SirDuke
Geek Apprentice
 
SirDuke's Avatar
 
Join Date: Jun 2007
Location: Greece
Posts: 148
Default

well i didn't check for your answer sooner and in the meantime i found another (more complex) workaround. I created a var called "isClicked" in the CellRenderer and inside the TreeCellRenderer i have an if statement that renders a different color based on this boolean var. So in my click handler i just do:

ActionScript Code:
var cr:TreeCellRenderer = mainMenu.myTree.itemToCellRenderer(e.item) as TreeCellRenderer; cr.isClicked = true;
then store in a variable the last node clicked and in the next click i set the previousNode.isClicked to false and the new node to true...

I figured it had to be with a variable inside the cellRenderer cause no matter what color i set it to, in the next redraw (click) it was reset to the cellRenderer's default.

As far as i'm concerned this is done for me. It might be overkill, but since it works, it's okay for this project. However if you need anything else feel free to ask.Thanx for your attention and of course for the component (next version: animation)
SirDuke is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
preloaders?!?! doing weird stuff... jacoflash ActionScript 1.0 (and below) 1 03-15-2005 05:02 PM
fscommand .msi .bat weird stuff :( [CVX] lucas ActionScript 2.0 1 02-18-2005 03:09 AM
Weird Flash Stuff jfharper Other Flash General Questions 5 06-15-2004 02:59 PM
Weird Stuff!! maydays Other Flash General Questions 4 06-12-2004 09:10 PM
weird stuff... BEANZ ActionScript 1.0 (and below) 5 02-14-2002 11:03 AM


All times are GMT. The time now is 10:55 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.