Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Button state always null in own skin

Posted on 2011-02-10
4
Medium Priority
?
686 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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

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…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

730 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