PDA

View Full Version : [AS3] mouseover in cell renderer


miles_holt
12-05-2009, 08:34 PM
Hi,

I have a cell renderer which determines the look of a list component called playList. I'm trying to have it so that when the mouse goes over an item/index, it changes its style and font.

At the moment I cant get it to work correctly I'm getting this error,

1061: Call to a possibly undefined method addEventListener through a reference with static type fl.controls.listClasses:ListData.

Here is the code for the cell renderer:

package{

import flash.events.*;
import fl.events.ListEvent;
import flash.display.Sprite;
import flash.geom.ColorTransform;
import fl.controls.listClasses.CellRenderer
import flash.text.TextFormat;
import flash.filters.BevelFilter;
import fl.managers.StyleManager

public class MyCellRenderer extends CellRenderer{
private var cTfm:ColorTransform = new ColorTransform(0, 12, 9, 3, 0x74, 0xFE, 0xF3);
private var emptyTfm:ColorTransform = new ColorTransform();



override protected function drawBackground():void{
super.drawBackground();
if(background){

if(listData.index == 0){
(background as Sprite).transform.colorTransform = cTfm;
var format:TextFormat = new TextFormat("SF Arborcrest Heavy", 12, 0xFFFFFF);
this.setStyle("textFormat", format);
this.filters = [new BevelFilter()];
this.mouseEnabled = false;
} else {
listData.addEventListener(ListEvent.ITEM_ROLL_OVER ,over);
(background as Sprite).transform.colorTransform = emptyTfm;
var format2:TextFormat = new TextFormat("SF Arborcrest Heavy", 12, 0xFFFFFF);
this.setStyle("textFormat", format2);

}
}

}

private function over (e:ListEvent):void{
var format3:TextFormat = new TextFormat("Arial", 8, 0xFFFFFF);
this.setStyle("textFormat", format3);
}

}


}

I'm not even sure if this is the best way to write it. Any help would be appreciated. m

miles_holt
12-05-2009, 09:55 PM
okay, ive made a few amendments and got it to trace, so the function is responding, its just not showing anything.

package{

import flash.events.*;
import fl.events.ListEvent;
import flash.display.Sprite;
import flash.geom.ColorTransform;
import fl.controls.listClasses.CellRenderer
import flash.text.TextFormat;
import flash.filters.BevelFilter;
import fl.managers.StyleManager

public class MyCellRenderer extends CellRenderer{
private var cTfm:ColorTransform = new ColorTransform(0, 12, 9, 3, 0x74, 0xFE, 0xF3);
private var emptyTfm:ColorTransform = new ColorTransform();
// public var playList:List = listData;



override protected function drawBackground():void{
super.drawBackground();
if(background){

if(listData.index == 0){
(background as Sprite).transform.colorTransform = cTfm;
var format:TextFormat = new TextFormat("SF Arborcrest Heavy", 12, 0xFFFFFF);
this.setStyle("textFormat", format);
this.filters = [new BevelFilter()];
this.mouseEnabled = false;
} else {
this.addEventListener(MouseEvent.MOUSE_OVER,over);
(background as Sprite).transform.colorTransform = emptyTfm;
var format2:TextFormat = new TextFormat("SF Arborcrest Heavy", 12, 0xFFFFFF);
this.setStyle("textFormat", format2);

}

}

}

public function over (e:MouseEvent):void{
var format3:TextFormat = new TextFormat("Arial", 8, 0xFFFFFF);
this.setStyle("textFormat", format3);
trace ("over worked");
}



}


}

miles_holt
12-05-2009, 10:55 PM
now it is showing something, just for some reason the font is not changing on the "over" function...

package{

import flash.events.*;
import fl.events.ListEvent;
import fl.controls.Label;
import flash.display.Sprite;
import flash.geom.ColorTransform;
import fl.controls.listClasses.CellRenderer
import flash.text.TextFormat;
import flash.filters.*;
import fl.managers.StyleManager

public class MyCellRenderer extends CellRenderer{
private var cTfm:ColorTransform = new ColorTransform(0, 12, 9, 3, 0x74, 0xFE, 0xF3);
private var emptyTfm:ColorTransform = new ColorTransform();
// public var playList:List = listData;



override protected function drawBackground():void{
super.drawBackground();
if(background){

if(listData.index == 0){
(background as Sprite).transform.colorTransform = cTfm;
var format:TextFormat = new TextFormat("SF Arborcrest Heavy", 12, 0xFFFFFF);
this.setStyle("textFormat", format);
this.filters = [new BevelFilter()];
this.mouseEnabled = false;
} else {
this.addEventListener(MouseEvent.MOUSE_OVER,over);
this.addEventListener(MouseEvent.MOUSE_OUT,out);

(background as Sprite).transform.colorTransform = emptyTfm;
var format2:TextFormat = new TextFormat("SF Arborcrest Heavy", 12, 0x999999);
this.setStyle("textFormat", format2);

}

}//if(background)

}//protected function

public function over (e:MouseEvent):void{
var format3:TextFormat = new TextFormat("Arial", 8, 0xFFFFFF);
this.setStyle("textFormat", format3);
this.filters = [new BevelFilter()];
this.filters = [new GlowFilter()];
trace ("over worked");
}

public function out (e:MouseEvent):void{
var format3:TextFormat = new TextFormat("Arial", 8, 0xFFFFFF);
this.setStyle("textFormat", format3);
this.filters = [];
trace ("out worked");
}



}//class