Solved

Button state always null in own skin

Posted on 2011-02-10
4
678 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
  • 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy &  paste option in flex air application 20 887
calling one function after another 4 309
debugger flash 10 622
Adobe URL is default to local hosts in my Mac Air 13 547
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…
Giving access to ESXi shell console is always an issue for IT departments to other Teams, or Projects. We need to find a way so that teams can use ESXTOP for their POCs, or tests without giving them the access to ESXi host shell console with a root …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

829 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