Hello, how hard can it be to add a simple underline on rollover, well… HARD!
I’m currently working on a simple xml reader. It’s almost finished except for 1 little tiny thingy.
You can see the reader here http://www.animea.net/gertjan/.
It does nothing special, it just goes to a next image every 8000ms (specified thru flashvars) and it has a title and some info.
The client wants a underline underneath the title on rollover, I said okay fine.
Then my nightmare started
For some unexplainable reason I only get the rollover to function on the last created image.
I’ll explain how my actionscript is structured below.
My documentclass consists of a “ImageViewer class”, a “Navigator class” and a Timer.
The Navigator has 2 buttons that call or a imageViewer.prev(); function, or a imageViewer.next(); function. Nothing special there.
The ImageViewer class.(> Sprite)
The ImageViewer receives a _xmlList provided by the documentclass.
I’ll look in the _xmlList and for each <item> I created a new “NewsImage class” instance (which also is a Sprite), and throws it in an Array. See below.
for(var i:int = 0; i < _xmlList.length( ) ;++i) {
var image:NewsImage = new NewsImage( _xmlList*, _h );
itemArray.push( image );
this.addChild( image );
}
Nothing special there, I guess.
The NewsImage class (as you can see above) receives one from the _xmlList and filters out the tag.
public function NewsImage( xml:XML, h:Number )
{
_xml = xml;
_sh = h;
_container = new Sprite( );
addChild( _container );
imageLoader = new Loader( );
imageLoader.addEventListener( IOErrorEvent.IO_ERROR, loadingError );
imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadingComplete );
imageLoader.load( new URLRequest( _xml.image ) );
}
When it has finished loading the URL it does the following:
private function loadingComplete(e:Event):void
{
_container.addChild( imageLoader );
infoPanel = new InfoPanel( _xml );
infoPanel.y = _sh - infoPanel.spaceNeeded;
addChild( infoPanel );
}
So it creates another class called “InfoPanel” (Sprite again).
The only thing infoPanel does is it pulls out an Sprite from the libary (bitmap in a Sprite) and adds to TextField’s to itself with text out of the xml.
So far so good, no problems here.
This is how the constructor looks like:
public function InfoPanel(xml:XML)
{
_xml = xml;
_title = _xml.title;
_info = _xml.text;
//this is a function that creates 2 textfields, pulls an image out of the libary and returns a Sprite.
info = infoBox( _title.toUpperCase( ), _info );
info.buttonMode = true;
info.addEventListener( MouseEvent.ROLL_OVER, rollOverBox );
info.addEventListener( MouseEvent.ROLL_OUT, rollOutBox );
addChild( info );
}
The added eventlisteners looks like this:
private function rollOverBox(e:MouseEvent):void
{
trace( "over" );
title_fmt.underline = true;
tf_title.setTextFormat( title_fmt );
}
private function rollOutBox(e:MouseEvent):void
{
trace( "out" );
title_fmt.underline = false;
tf_title.setTextFormat( title_fmt );
}
The rollover works fine, traces nicely “over” and “out”, on all the images.
The setTextFormat only seems to work on the last created image.
Again, you can see it in action here:
http://www.animea.net/gertjan/
If anyone, has ANY idea what this could be, please share, I’m desperate for an answer
Just check the last image added, 1 to the left, the rollover works fine there…
[SIZE=“1”](Sorry for my long story, it’s the only way to make clear how I structured my code)[/SIZE]