|
-
Disabling a list item onclick
I have a List() component populated by a data provider. The list has a custom style set to an external AS class that extends CellRenderer. What I want to do is when a list item is clicked, I want to gray out that item. I have the styles for graying it out, I just need to set the style for the clicked list item. I asked this question once before and got an answer in this thread:
http://board.flashkit.com/board/show...hreadid=745726
The problem is that solution doesn't handle onclicks, just static lists. So how do I capture the onclick and set the styles for the list item so that it's gray when you click on it?
-
Bumping from page two, no responses yet.
-
Ok, let's say I have a CellRenderer class for the list like such:
package {
import fl.controls.listClasses.CellRenderer;
class ListBackground extends CellRenderer {
public function ListBackground() {
//...
}
}
}
}
Is it possible to capture the onclick of a list event item in there and do like listItem.setStyle("upSkin", myCustomDisabledSkin)
?
-
Senior Member
Ok,
I figured it out. Create a class with this script, which is the cellrenderer class:
PHP Code:
package { import fl.controls.listClasses.CellRenderer; import fl.controls.listClasses.ICellRenderer; public class MyCellRenderer extends CellRenderer implements ICellRenderer { private static var _myArray:Array=new Array; public function MyCellRenderer () { super (); } /* * This method overrides the inherited drawBackground() method and adds the GreyColor from * the MovieClip GreyColor to each selected index. */ override protected function drawBackground ():void { for (var count:int=0; count<=_myArray.length; count++) { if (_listData.index == _myArray[count]) { setStyle ("selectedUpSkin",GreyColor); setStyle ("upSkin", GreyColor); } super.drawBackground (); } } public static function selectIndex (sid:int):void { _myArray.push(sid); } } }
This is the fla file example script, when you have a list component "myList" on the timeline.
PHP Code:
myList.addItem({label:"Burger"}); myList.addItem({label:"Fries"}); myList.addItem({label:"Chips"}); myList.addItem({label:"Chicken"}); myList.addEventListener(Event.CHANGE,changed); function changed(event:Event) { MyCellRenderer.selectIndex(event.currentTarget.selectedIndex); myList.setStyle("cellRenderer",MyCellRenderer); }
The reference to each row is _listData.index.
Last edited by cancerinform; 05-13-2008 at 09:26 AM.
- The right of the People to create Flash movies shall not be infringed. -
-
Sweet, I will try that out tomorrow. Thanks!
Also, I think it's possible to do only in the CellRenderer class. I had this same functionality working on a Flash file but I accidentaly deleted the AS file that went with it. It was working without any event handlers in the actual flash movie, all done in the cellrenderer class. I just can't for the life of me figure out how I did it :P
-
Senior Member
Actually you need to initiate the renderer only once:
myList.setStyle("cellRenderer",MyCellRenderer);
myList.addEventListener(Event.CHANGE,changed);
function changed(event:Event)
{
MyCellRenderer.selectIndex(event.currentTarget.sel ectedIndex);
}
- The right of the People to create Flash movies shall not be infringed. -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|