How can I scale the icon of a Spark button? - apache-flex

I have a Spark button with an icon, and I want to be able to scale it, as with an Image component, but I can't find any property for that. Is there any way to achieve that? Thanks.

You could look into Button Class, and then write a custom Class extends Button and implement what you want.
I remember that the icon is displaied by BitmapImage, you could get it's reference and then scale that.

If you want to scale the icon; but not the button; you can do so by accessing the properties directly on the iconDisplay skin part:
myButtonInstance.iconDisplay.scaleX = 2;
myButtonInstance.iconDisplay.scaleY = 2;
myButtonInstance.iconDisplay.scaleZ = 2;
The properties used for scaling are scaleX, scaleY, and scaleZ. The BitMapImage also has a property called scaleMode

Related

Change the label and icon placement for a Flex Spark ButtonBar control

Im trying to create a custom skin for ButtonBarButton. I need to create vertical layout of icon and label placement like in this exapmle for mx ButtonBar component: http://blog.flexexamples.com/2008/01/08/changing-the-label-placement-for-a-flex-buttonbar-control/
Unfortunately there is no "labelPlacement" property in spark components and i cant find a way to change the default BasicLayout layout for custom SparkButtonSkin either.
Found a solution where you set icon position with function 'setStyle'
(in spark skin initializer Handler)
protected function sparkbuttonskin_initializeHandler(event:FlexEvent):void
{
setStyle("iconPlacement", IconPlacement.TOP);
}
There is an iconPlacement property in Spark Button. But if you want to put Buttons inside of ButtonBar component you have to do something like this http://blog.flexexamples.com/2009/07/28/displaying-icons-in-a-spark-buttonbar-control-in-flex-4/

Flex: Hide (or Remove) Label Text without Changing the Button Size

I have a button with variable-length of label text. I have a User Setting that can turn on or off the label text on this button.
How can I implement this?
NOTE: the button's background has a gradient color.
I tried using BlendMode.LAYER, no luck;
I tried using Button.resizeHandler
private function resizeHandler(event:ResizeEvent):void
{
if (event.oldWidth > this.width)
this.width = event.oldWidth;
if (event.oldHeight > this.height)
this.height = event.oldHeight;
}
but it only worked if the initial UserSetting value is true.
How about embedded font? I don't know how to apply it to button
You can use the property minWidth and maxWidth. minWidth to specify the minimum width that the button should have. and maxWidth to specify the maximum width the button can have.
You can extend mx.controls.Button to add a show/hide label function. The text field is a protected property so you can just set the visibility on/off in your function. Leave Flex to measure everything correctly itself.
If you want to grow/shrink the button when the text is on or off, you can also set the button width. You will have to calculate the width based on the textfield width.
What happens if you just set the button's width? That way, it should be a constant width no matter what you set as the label.
Most likely width is being calculated in the updateDisplayList method. So, code in your resize handler may be being reset at the next render event.

Change color of a Flex 4 spark Button

Is there an easy way to change the background color of a Flex 4 spark Button without messing with skins?
UPDATE: ok, figured it out, simply set the chromeColor attribute of the Button mxml.
For spark components, you can use chromeColor style:
<s:Button chromeColor="0xff0000" label="chrome red"/>
You can change the color style of the button. You can also have a bitmap fill.
Update: The above methods do not change the background.
Easiest way to change the background, you can use - opaqueBackground property.
Here is another way to change the background of a button without changing its skin -
1. Create a group with a rectangle and your button.
2. Set opaqueBackground of your button to null.
3. Make width and height of rectangle to 100%
4. whatever color you fill the rectangle with is the background of your button.
This can also be done via code like :-
btnID.addEventListener(MouseEvent.MOUSE_OVER, textChange);
btnID.addEventListener(MouseEvent.MOUSE_OUT, textChangeback);
private function textChange(event:MouseEvent):void
{
btnLinkDelete.setStyle("color", 0xFFFFFF)
btnLinkDelete.setStyle("chromeColor", 0x535151)
}
private function textChangeback(event:MouseEvent):void
{
btnLinkDelete.setStyle("color", 0x000000)
btnLinkDelete.setStyle("chromeColor", 0xfcffff)
}
I am posting it, if anyone want to change background color on mouse hover.

Flex ProgressBar component problem

I am trying to use the ProgressBar Flex component inside a custom Actionscript 3.0 component derived from the UIComponent class. I have set the minimum and maximum values etc.
_progressBar = new ProgressBar();
_progressBar.label = "Loading";
_progressBar.minimum = 0;
_progressBar.maximum = 100;
_progressBar.direction = ProgressBarDirection.RIGHT;
_progressBar.mode = ProgressBarMode.MANUAL;
The component shows the "Loading" text but not the loading bar.
Anything like _progressBar.setProgress(20, 100) does not have any effect on the code. Any ideas why this is not working?
The problem is that I was adding the component to a UIComponent. Flex components need to be added to something derived from a container like a Canvas. I could not get buttons to display in my custom component derived from UIComponent. Changing it to Canvas fixed the issue. Hope this helps someone.
There is no problem with the current code you have provided (it works fine in an individual instance).
Perhaps the problem lies in your custom AS3.0 component, but without further information it's not possible to assist you.

Flex 3: HBox children Scrolling with buttons

I have an HBox with width=500.
I actually want to add two arrows buttons that will scroll the contents of the HBox.
But when I turn HBox's scroll policy to off, I can't scroll it programmatically using horizontalScrollPosition.
What should i do now?
Thanks
I've hacked together this custom HBox that you could use. Simply set horizontalScrollPolicy to either "on" or "auto". I really haven't tested it all that much, works for a simple test I did...
public class CustomHBox extends HBox
{
override public function validateDisplayList():void
{
super.validateDisplayList();
if (horizontalScrollBar)
horizontalScrollBar.visible = false;
}
}
Scroll bars will not be displayed when scrollPolicy is turned off.
I think for what you want, you want to subclass ScrollBar make it look and feel the way you would like, then set it on your Container.horizontalScrollBar
I'm no Flex expert, but this is possible without too much trouble (using Flex SDK 3.2, anyway). You're right - when you turn off the horizontalScrollPolicy, the maxHorizontalScollPosition is set to 0, UNLESS you specify both a width value AND a maxWidth value. Then, maxHorizontalScrollPosition will again contain a useable value, and you'll be able to programmatically set the horizontalScrollPosition.

Resources