...

View Full Version : Flex help? Change text colour on MouseOver?



loki421
02-17-2009, 11:34 AM
Hi all!

This is my first post here so hi everyone :D

I've recently started playing around with Flex 3, i've always been interested in Flash development but never really found the time to sit down and do some learning, until now :p

So my understanding of AS3 is very poor, i'm picking it up slowly but everyday is an uphill climb!

So i'm having a play around in Flex and was wondering if it's possible to change the text colour of a label or simular on MouseOver?

I have this so far:


<mx:Label text="simple text" id="myLabel" color="#000000" click="currentState='stateOne'"/>


Now obviously this is going to be acting as a link so the user can visit the 'stateOne' state, but i would like it to change colour on rollover so that the user can see it's a link, I don't want buttons all over the place.

So i thought that maybe this would do the trick:


<mx:Label text="simple text" id="myLabel" color="#000000" click="currentState='stateOne'" mouseOver="text.color = #ffffff"/>


But it didn't, i just get a syntax error 1093. So then i thought i'd try and add a private function for the mouseOver event, but that just went horribly wrong! :p As i said my AS3 is terrible!

So i was just wondering if anyone out there knows a little Flex or AS3 that i could use in-line. If you're going to suggest using a function i'm afraid you'll have to bear with me and explain it a little as i'm still a total newbie!! :D

Many thanks in advance to anyone who offers help, all suggestions will be gratefully received! :thumbsup:

gnomeontherun
02-17-2009, 12:37 PM
Welcome, and this belongs in the Flex forum here just for future notices.

Try this, otherwise my suggestion is to always google the error code. I found this nice article

http://curtismorley.com/2007/08/25/flash-cs3-flex-2-as3-error-1093/


<mx:Label text="simple text" id="myLabel" color="#000000" click="currentState='stateOne'" mouseOver="text.color = 0xffffff"/>

loki421
02-17-2009, 01:36 PM
mmm... getting an odd error now:

Access of undefined property text

Why would this be happening if it's in line?

gnomeontherun
02-17-2009, 02:39 PM
Sorry I should have been more clear, I don't know Flex. But the error says that there is no property 'text' so it should not be included.


mouseOver="color = 0xffffff"/>

loki421
02-17-2009, 06:00 PM
Ha, now it's not happy about the color property lol, it's the same error but this time says 'color'. Maybe it just can't be done to text? I've search the Adobe Flex help and found no reference to changing color on rollover.

Maybe it's time to admit defeat... ???

Or perhaps it could be done through a function..... I'll do some more Googling, if i find the answer i'll post back so others can see how to do it. :D

gnomeontherun
02-18-2009, 08:50 AM
http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_2.html

Might be a good start, perhaps you have to have a listener instead?

loki421
02-19-2009, 07:35 PM
Right, after a few days of self teaching with functions etc, i have come up with this:



private function initilizeApplicationFunction():void
{
myButton.addEventListener(MouseEvent.CLICK, myClickHandler);
messageLabel.addEventListener(MouseEvent.MOUSE_OVER, textChange);
messageLabel.addEventListener(MouseEvent.MOUSE_OUT, textChangeback);
}

private function textChangeback(event:MouseEvent):void
{
messageLabel.text = 'Label';
}


private function textChange(event:MouseEvent):void
{
messageLabel.text = 'Click to visit...';
}


So obviously you need to call the initilizeApplication (initApp) at start up, but the basics is that the text will chage to 'Click here to visit....etc etc.

For some reason i can't access the color property of the label in the function, is there a specific property that provides the colour? It's really starting to bug me now :p

Any suggetions would be great! If not don't worry, at least there's a possible solution for people to see here :D

gnomeontherun
02-20-2009, 09:44 AM
Try this.


private function initilizeApplicationFunction():void
{
myButton.addEventListener(MouseEvent.CLICK, myClickHandler);
messageLabel.addEventListener(MouseEvent.MOUSE_OVER, textChange);
messageLabel.addEventListener(MouseEvent.MOUSE_OUT, textChangeback);
}

private function textChangeback(event:MouseEvent):void
{
messageLabel.setStyle("color", 0xFF00FF)
}


private function textChange(event:MouseEvent):void
{
messageLabel.setStyle("color", 0x00FFFF)
}

loki421
02-20-2009, 10:54 AM
You are my hero!!!! That works a treat, thank you!

So much to learn... didn't even cross my mind to use a style, got too caught up in functions and properties :p

You're a star, thanks!

Just for future reference, where is the Flex forum here? I've had a quick look and can't see it, just for future posts (no doubt they'll be many :p lol).

Thanks again! :D :D :D

gnomeontherun
02-20-2009, 11:03 AM
Awesome, I might just go and start to learn Flex too :)

Its a subforum of the Flash, so go to Flash forum and its at the top.

http://www.codingforums.com/forumdisplay.php?f=63

loki421
02-20-2009, 11:26 AM
It's an amazing program! Takes a little getting used to, but the things you can do with it.... amazing.

I've always liked flash but found the process very long winded, Flex eliminates that to a certain extent, and has various predefined elements that save you a lot of time developing!

Just found out how to talk to ColdFusion with it too, and now i'm one very happy bunny! :p

Look out world!!! :D :D

Oh, thanks for the link too :p

jerry62704
02-20-2009, 04:00 PM
Awesome, I might just go and start to learn Flex too :)

Its a subforum of the Flash, so go to Flash forum and its at the top.

http://www.codingforums.com/forumdisplay.php?f=63

Start here. (http://www.adobe.com/devnet/flex/videotraining/)

micksatana
02-04-2011, 08:13 AM
don't need to add into as3 script, you can code in mxml directly


<s:Lable mouseOver="{this.setStyle('color', 0xDC5A82)}" mouseOut="{this.setStyle('color', 0xFFFFFF)}" text="TEST" />



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum