Solved

Button state always null in own skin

Posted on 2011-02-10
4
679 Views
Last Modified: 2012-06-21
Hi,

I've a own ButtonSkin using an UI component inside:
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:fb="http://ns.adobe.com/flashbuilder/2009">
....
      <!-- states -->
      <s:states>
            <s:State name="up" />
            <s:State name="over" />
            <s:State name="down" />
            <s:State name="disabled" />
      </s:states>
....
<cc:DrawStyle width="100%" height="50%" bottom="1" left="3" right="3" />
...
</s:SparkSkin>

cc:DrawStyle  is an own ActionScript drawing something within the button.
The matter is that this.currentState is ever null - the only way I can figure out the state is a workaround like (this.owner as UIComponent).currentState .

I like to set styles using CSS but this works only for normal state and not for something like:
cc!DrawStyle:over

I think the problem is that currentState is null, isn't it?
What's the right way to do?

Thanks

Andre
package cc
{
	import flash.display.*;
	import flash.geom.*;
	
	import mx.core.UIComponent;
	
	
	public class DrawStyle extends UIComponent
	{
		public function DrawStyle()
		{
			super();
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			this.graphics.clear();

			switch((this.owner as UIComponent).currentState)
			{
				case "over":
					break;
				case "down":
					break;
				case "disabled":
					break;
			}
			trace(this.currentState);
			
		}
	}
}

Open in new window

0
Comment
Question by:andre72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 34870054
What exactly do you want to be able to do?

Do you want to make DrawStyle be set to the same state as the component that contains it?
0
 

Author Comment

by:andre72
ID: 34872918
The matter is that I can't set different colors using CSS.
I think the currentState is the reason for ...

So:
cc|DrawStyle
{
  MyProp: #000000;
}

works fine but:
cc|DrawStyle :over
{
  MyProp: #FF0000;
}

doesn't work ....

However:
<cc:DrawStyle width="100%" height="50%" bottom="1" left="3" right="3" MyProp="#000000" MyProp.over="#FF0000" />

Works fine ...

When I try to solve this I figured out that currentState is allways null and I don't know why.

Thanks

Andre
0
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 34874027
The difference is that in your CSS you set the style depending on the state of your DrawStyle component. In your mxml styling you set it's color based upon the state of the component containing it. Try something like this:
cd|MyButton cc|DrawStyle
{
  MyProp: #000000;
}

cd|MyButton:over cc|DrawStyle 
{
  MyProp: #FF0000;
}

Open in new window


Just replace cd|MyButton with the name of the component the skin you posted is the skin for.
The difference is that in my case the first css is used per default. If the MyButton component is in "over" state however, the second rule is used to style any DrawStyle children of that MyButton.

Hope it works :-)
0
 

Author Closing Comment

by:andre72
ID: 34888821
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Read our guide on how to survive being on-call.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question