Solved

Button state always null in own skin

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Flex organization chart 5 612
Is this doable in Flex/AIR - pointers? 5 269
Refresh Image 2 30 945
AS3 parent function 3 671
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…
February 24, 2017 — On February 23, Travis Ormandy, a vulnerability researcher at Google, reported on Twitter (https://twitter.com/taviso/status/834900838837411840) that massive stores of data have been leaked by CloudFlare, a company that provide…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

773 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