Showing posts with label flex. Show all posts
Showing posts with label flex. Show all posts

Monday, April 06, 2009

Today I discovered the "parseNumberString()" function.

I have a textInput that is a formatted currency value. I needed to convert it to a number for calculations. I could have used a regular expression to remove the currency formatting characters. But then I found the "parseNumberString()" function.

Flex help says the parseNumberString() extracts a number from a formatted String. It examines the string from left to right and returns the first number sequence. It ignores thousands separators and includes the decimal and numbers trailing the decimal.

Here's a sample of how to use the function

import mx.formatters.NumberBase;
...
...

public function foo():void
{

var nb:NumberBase = new NumberBase();
var numValue:Number = Number( nb.parseNumberString(strCurrencyValue) );
}

Friday, January 09, 2009

The answer to my Flex 3 / Flash CS4 skinning question

Thanks to Juan Sanchez for providing me the solution when he commented on my previous blog post. He wrote...
"Try using a ClassReference for the Image source that references the skin class name in your SWC instead: http://scalenine.com/blog/2008/07/08...r-flash-skins/
source: ClassReference("Image_source");"

It worked perfectly!!!

So the CSS now looks like this:
Button { skin: Embed(skinClass="Button_skin"); }
Canvas { backgroundImage: Embed(skinClass="Canvas_backgroundImage"); }
Image { source: ClassReference("Image_source"); }
And the MXML now looks like this:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:com="com.*">
<mx:Style source="skins.css"/>
<!--- Canvas background is set using CSS --->
<Canvas>
<!--- Button skin is set using CSS --->
<mx:Button />
<!--- Now the image is set using CSS --->
<mx:Image source="{Image_source}"/>
</Canvas>
</mx:Application>

Thursday, January 08, 2009

I need help with Flex skinning using Flash CS4

I am learning how to create skins for my Flex apps in Flash CS4 and I'm finding there's multiple ways to do so.

In Flex 2 you would use ActionScript to embed a SWF that contains the skins for you app. You can do the same in Flex 3, but Adobe added the "Import Skin Artwork" feature which imports a SWC, not a SWF.

What I am trying to figure out is how to set the source of an <image> tag to the image symbol found in an "imported SWC."

To clarify my issue I'll elaborate further...

First I read...

They were all very helpful, but they showed a couple of ways to achieve the same thing, and most of the examples focused on skinning a button.

Here are the the basics that I learned:
1) Create your skin in Flash CS4.
2) Convert the skin to a symbol.
3) Publish the SWF or SWC...

  • For Flex 2:
    • Set the each symbols linkage to "Export for Actionscript."
    • Publish to a SWF that's embeded into the Flex 2 app.
  • For Flex 3:
    • Use "Convert Symbol to Flex component" (which is a available after installing the "Flex Component Kit for Flash CS3").
      Or, you could also set the each symbols linkage to "Export for Actionscript."
      I don't fully understand the difference yet.
    • Publish to a SWC and use the Flex "Import Skin Artwork" feature.

Where they differ is how to get the skin assets into flex probably due to differences between Flex 2 and 3.

In Flex 2 you would use code similar to this...


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
[Embed(source="assets/skins.swf", symbol="Canvas_backgroundImage")]
[Bindable]
public var test_background:Class;

[Embed(source="assets/skins.swf", symbol="Image_source")]
[Bindable]
public var test_image:Class;

[Embed(source="assets/skins.swf", symbol="Button_skin")]
[Bindable]
public var test_button:Class;
]]>
</mx:Script>

<mx:canvas backgroundImage="{test_background}" />
<mx:Image source="{test_image}" />
<mx:Button icon="{test_button}" />
</mx:Application>



You can use the same code in Flex 3, however Adobe introduced a new feature - "Import Skin Artwork." It's found under the File menu: File > Import > Skin Artwork...


When you "Import Skin Artwork" you have to:

1) Use a specific naming convention when creating your symbols in Flash.

2) Publish to a SWC (not a SWF).


Why publish to a SWC? The "Import Skin Artwork" functionality looks for a SWC which it will add to the library path of your Flex project. It also parses the symbol names found in the .SWC to create the CSS file used to apply the skins to your flex components.


First I created a Flash CS4 project named "skins," and I added three images and created the following symbol names:

  • Button_skin

  • Canvas_backgroundImage

  • Image_source


When I was done, I published my project creating the "skins.swc" file.


In Flex Builder 3 I imported "skins.swc" and Flex created the following "skins.css" File:


Button { skin: Embed(skinClass="Button_skin"); }
Canvas { backgroundImage: Embed(skinClass="Canvas_backgroundImage"); }
Image { source: Embed(skinClass="Image_source"); }





Note how the symbol names were parsed into the css:

  • Button_skin >> Button { skin: ...

    where "skin" is a style member of the Flex <mx:Button> component

  • Canvas_backgroundImage >> Canvas { backgroundImage: ...

    where "backgroundImage" is a style member of the Flex <mx:Canvas> component

  • Image_source >> Image { source: ...

    where "source" is a property (not a style member) of the Flex <mx:Image> component.

    This is where I believe my problem is, "source" is a property not a style member.


For more on this, read "Naming skin assets" on page 3 of the pdf "Importing Skins into Flex Builder"


Now for the MXML:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:com="com.*">
<mx:Style source="skins.css"/>
<!--- Canvas background is set from the CSS --->
<Canvas>
<!--- Button skin is set from the CSS --->
<mx:Button />
<!--- Image does not displayed --->
<mx:Image />
</Canvas>
</mx:Application>



I think because "source" is a property of the Flex <mx:Image> component and not a style member, it is being ignored.

However, I cannot code: [Embed(source="assets/skins.swc", symbol="Image_source")] because this throws compile error.


So, Is there a way to do this with an imported SWC?

Or do I have to create an imported SWC for skinning components and embed a SWF for image assets?


Thanks and I hope you may have learned something after reading all this as well!


Chris from flexdojo




Monday, January 05, 2009

Unable to transcode xxx.swf

Let me start by saying I’m an experienced Flex developer, but a Flash CS4 newbie.

I want to begin using Flash CS4 to create asset libraries that will be used to skin my flex apps. After creating a test swf containing some assets, I tried embedding the swf in a Flex 3 app and kept getting this error - “Unable to transcode xxx.swf.” I spent an entire day trying to resolve the problem. I searched the web for hours, but found nothing helpful.

Earlier, I installed the "Flex Skins" template into Flash CS4. I went back to that project hoping it would provide a clue. It was then I noticed the "linkage" column in the library panel. And that's how I learned the linkage on each individual symbol must be set as “Export for ActionScript” for Flex to find the symbol definitions.

Here's what messed me up...

Instead of just reporting that it can’t find the symbol definitions, Flex also reports that it can’t transcode the SWF. That led me to believe there was something wrong with the SWF. And off I went, on a wild goose chase looking for anything that would explain why flex could not embed the SWF. But in the end it was just a symbol definition problem.

I hope this helps save others hours of frustration!

Monday, August 27, 2007

My Netvibes Flex Tab

My Netvibes Flex Tab is a collection of Adobe Flex feeds.
To add it to you Netvibes account click the image below.
 Add my Flex tab to your Netvibes

Friday, June 15, 2007

How to change focus with the enter key

Here is a simple Flex app that shows how to change the focus of of several textInput components with the enter key. The one thing I have not yet figured out is why, after the Alert window is closed, the focus jumps back to the login button instead of the "fullName" text input field.

enterKeyTest.mxml

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
    <local:focusLoop />
</mx:Application>

focusLoop.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
    <mx:Script>
    <![CDATA[
        ////////////////////////////////////////////////////////////
        import mx.events.CloseEvent;
        import mx.core.UITextField;
        import flash.ui.Keyboard;
        import mx.controls.Alert;
        ////////////////////////////////////////////////////////////
        private function initApp():void
        {
            this.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
        }
        ////////////////////////////////////////////////////////////
        private function keyHandler(event:KeyboardEvent):void
        {
            if(event.keyCode == Keyboard.ENTER)
            {
                if(event.target is UITextField)
                    drawFocus(true);
                else if(event.target.id == "myBtn")
                    showAlert();
            }
        }
        ////////////////////////////////////////////////////////////
         override public function drawFocus(isFocused:Boolean):void
        {
            focusManager.getNextFocusManagerComponent().setFocus();
        ////////////////////////////////////////////////////////////
        }       
        private function showAlert():void
        {
            Alert.show('Clicked Login Button!', '', Alert.OK, this, alertListener);           
            myBtn.focusEnabled=false;
        }
        ////////////////////////////////////////////////////////////
        private function alertListener(eventObj:CloseEvent):void
        {
            fullName.setFocus();
        }   
    ]]>
    </mx:Script>
        <mx:Form>
        <mx:FormItem label="Name">
            <mx:TextInput id="fullName" width="100" focusOut="myBtn.focusEnabled=true"/>
        </mx:FormItem>
        <mx:FormItem label="Street">
            <mx:TextInput width="100" />
        </mx:FormItem>
        <mx:FormItem label="City">
            <mx:TextInput width="100" />
        </mx:FormItem>
        <mx:FormItem label="State">
            <mx:TextInput width="50" maxChars="2" />
        </mx:FormItem>
        <mx:FormItem label="Zip Code">
            <mx:TextInput width="50" maxChars="5" />
        </mx:FormItem>
        <mx:FormItem>
            <mx:Button id="myBtn" label="Login" />
        </mx:FormItem>
    </mx:Form>
</mx:VBox>

Wednesday, April 25, 2007

FMS - What I'm Learning about Client and Server Scripts

I have an MXML/AS3 component that calls some remote FMS1 methods, which works well. However, the client callbacks are not working.

Being an FMS newbie, I'm wondering if this is an AS2/AS3
2 issue. So, I turned to the O'Reilly book Programming Flash Communication Server to learn more.
In the pursuit of getting client callbacks to work, here is some of what I've learned about FMS and client scripting so far... 
Client-To-Server Calls
  • Each SWF that connects to FMS is called "The Client" and is referenced by the SSAS3 code via the "Client object."

  • Clients use the NetConnection.call(...) method to ask the server to do something for them. For the call to work the method on the server must have the same name and it must be attached to the server-side Client Object.
    For example...

    nc.call("getStreamLength", resultObject, name);

    - Where nc is the NetConnection object used to connect the client to FMS.
    - To process the results a handler method should to be defined.

  • Server-side methods must to be attached to the Client object to be invoked by a SWF (the Client).
    For example...

    // The new function object is attached to the client object
    // so that it can be called by the client.
    clientSWF.getStreamLength = function(name)
    {
      return Stream.length(name);
    };

  • SSAS also allows you to attach methods to the "Client.prototype" object4. This helps save memory and processor time on the server and every instance of that class (I.e. the Client class) will contain the attached methods automatically. For example...
    Client.prototype.getStreamLength = function (name)
    {
      return Stream.length(name);
    };

  • To sum up...
    • You can attach SSAS methods needed by every Client object to Client.prototype.
    • Alternatively, you can define SSAS methods on specific client instances. This is how you can allow access to specific SSAS methods for a subset of clients connected to the application.
Server-To-Server Call


  • For the server to call a client-side method, the method must be attached to a client-side NetConnection object.
    For example...

    nc.setStreamLength = function(value)
    {
       this.streamLength = value;
    };

This is where I think my problem is...
Somehow I have to attach my AS3 client-side method to the NetConnection object. But, the NetConnection object is a sealed class in AS3 (AS2 it is a dynamic class). So, I created a dynamic class (named "netConnect") that extends the NetConnection class and now I need to figure out the syntax to add an AS3 function object to a dynamic class.
(2007-04-25 - 3:30 PM CST)

The solution was pretty easy...
I just added a dynamic property to my netConnect class and then assigned my function statement to it.
(2007-04-25 - 5:26 PM CST)


Client-Side AS3:
/////////////////////////////////////////
private var nc:NetConnect = new NetConnect();
/////////////////////////////////////////
public function onCreationComplete():void
{


   var myTimer:Timer = new Timer(1000, 0);
   myTimer.addEventListener("timer", createConnection);
   myTimer.start();


}
/////////////////////////////////////////
private function createConnection():void
{
   if(!nc.connected)
   {
      nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
      nc.connect("rtmp:/testCallback");       // Local FMS Application
      nc.update = callBack;                       // Assign callBack() function
      this.connect(nc);
      nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
   }
}

/////////////////////////////////////////
public function callBack():void
{

   trace( "** The callBack() function was called by the server **" );
}


Server-Side AS2:
...
clientSWF.call("update", null);
...
FMS - Flash Media Server
AS2/AS3 - ActionScript Ver. 2 or 3
SSAS - Server Side ActionScript
The "Client.prototype" object is the base class of the Client object

Friday, April 13, 2007

Multiple "effectEnd" events from a parallel effect

I created a parallel effect with AS3...

var zoom:Zoom = new Zoom();
zoom.easingFunction = Exponential.easeIn;
zoom.duration = 1500;
zoom.zoomHeightFrom = 0.0;
zoom.zoomHeightTo = 1.0;

var fade:Fade = new Fade();
fade.easingFunction = Exponential.easeIn;
fade.alphaFrom = 0;
fade.alphaTo = 1;
fade.duration = 1500;

msgEffect = new Parallel();
msgEffect.targets = effectsArray;
msgEffect.addChild(zoom);
msgEffect.addChild(fade);
msgEffect.play();
I added a listener for when the effect ends...

addEventListener(EffectEvent.EFFECT_END, close);
Then I coded the following handler...

private function close(event:EffectEvent=null):void
{
visible = false;
mx.managers.PopUpManager.removePopUp(this);
dispatchEvent(closeEvent);
}
Even though the effects are part of a parallel effect sequence object, two "effectEnd" events are fired one for the Zoom and the other for the Fade.

I believe this occurs because the targets fire the "effectEnd" event, not the parallel effect sequence object.

It looks like I need some wrapper that says, "Hey, both effects in your parallel effect sequence object are done!" Seems odd though, shouldn't the parallel sequence object do that?

Well, here's my very cheesy fix for this problem. I changed the event handler as follows...

private function close(event:EffectEvent=null):void
{
  visible = false;
  mx.managers.PopUpManager.removePopUp(this);
  dispatchEvent(closeEvent);
  // Ignore any other "effectEnd" events.
  removeEventListener(EffectEvent.EFFECT_END, close);
}

Wednesday, April 11, 2007

Fading buttons and embedded fonts

To apply a fade effect to text you must use embedded fonts. I was going nuts trying to use an embedded font with buttons so the applied fade effect would work. After several failed attempts I found this post (thanks Jesse!).

In short, create a style that looks like this...
Button
{

embedFonts: true;

fontWeight: normal;

fontSize: 22;

fontFamily: YourEmbeddedFont;

}

Thursday, October 19, 2006

Adobe Flex 2.0 » VideoDisplay Borders - Part I

Rectangular borders are no problem for the Flex "VideoDisplay" component. However, radiused borders seem to be.

VideoDisplay is a composite component; An Actionscript class that extends UIComponent and adds a child "flash.media.Video" component. It contains a method named "createBorder()" that loads a border skin and adds it as a child underneath all other child components...

addChildAt(DisplayObject(border), 0);

As a result, the rectangular "flash.media.Video" component is on top of the border and the corners of the video rectangle overlay and extend beyond the VideoDisplay's radiused corners.

How can I get around this problem? I don't know yet, but I'm working on it!