Solved

Button state always null in own skin

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now