Actionscript 3

AS3: Yahoo Stocks, Flash and ColdFusion

01/02/2010 in RIA View Comments

After searching high and low for a good resource of semi-up-to-the-minute updated stock feeds I came to the conclusion that there aren’t any, for free anyway. I dug into the Google Finance and Data API’s, and made a lot of headway there writing the authentication methods in JavaScript, then in PHP, then in .NET…but was not able to pull something together (quickly) . I plan on revisiting that path, but I digress. I turned to the Yahoo file download that you access via http and it returns a .csv full of stock data from opening trade, current change, volume, etc. This was perfect but how do I convert that to a format that Flash can read?

I used the URLLoader method to load the data, converted it to an Array by splitting at the commas, and then loaded the different values I need by accessing a certain part of the array. This worked perfectly, locally, but then I placed it on our intranet (final resting place), and nothing showed up. Come to find out, the cross domain policies were preventing access to the file on Yahoo’s server. So to make things easier in the long run I wrote a proxy in ColdFusion that the Flash app calls to obtain the stock data. Enough of my explanations and on to the meat…

Read more

AS3: Trying out FDOT

01/02/2010 in RIA View Comments

Ted Patrick blogged yesterday that he released the latest build (32) of FDOT, a collection of AS3 classes that are created to make hard things easier to do. I have to say my first use of it did just that, taking an XML import from my normal 2 to 3 custom classes, custom events, etc. down to one basic line with a single method to handle callbacks. It’s hard for me to get out of the habit of using addEventListener’s basically everywhere, but literally within 10 minutes of downloading the latest build of FDOT I was loading in an XML dataset, transforming it to an Array (why? because I like to and it makes sorting easy), and tracing random data from the feed. I will say, I am sold and will be utilizing it whenever I can. Check out the code below, and visit Ted’s site and thank him for making this hard task easy…

You can grab the library here.

You can visit Ted’s blog post here.

Read more

Flex Framework: Using Mate to populate a datagrid with an ArrayCollection

01/02/2010 in RIA View Comments

Recently I have been learning to use and implementing the Mate Event based framework for Flex. I have to say it is very easy to pick up and will definitely be digging into it more as the days come. I am including a sample Flex project as a zip file in this post and won’t get into the fine details…unless I am asked to. In using Mate, one of the most important tips is to know what files to create and the process of using those files. For this demo I will be using the EventMap (of course…), and the Manager class. Below is the order or items needed and what they are used for.

Download source here.

Of course, learn more about Mate and get the framework here.

Mate and ArrayCollections

Read more

AS3: Creating custom events

01/02/2010 in RIA View Comments

Let’s say you are creating a custom data service provider that can be used by more than one class in your project, or even a portable re-usable class. A nice, clean way to instantiate the data service provider without getting a cart before the horse error (datagrid trying to populate with data that is not yet loaded, etc…), is to use a custom event. It is very easy to create a custom event, dispatch it and listen for it. This way you can have say your datagrid in an mxml file, import the data service provider that has a RemoteObject in it, and the populate the datagrid ONCE the RemoteObject returns data. How would the datagrid know the data is ready?? A custom event!

Below is a simple example of a custom event class, and an mxml file using the custom event. EventPractice.mxml imports the CustomEvent.as file, adds listeners for the custom event while the buttons each dispatch one of the custom events. You simply pass the string value of the CONST variable in the custom event as an argument in the CustomEvent.as constructor, e.g. “dispatchEvent(new CustomEvent(“cEvent01″));”.

Read more

AS3: Re-Usable TextFormat class

01/02/2010 in RIA View Comments

In this simple tip I provide an easy to use text formatting class. To use this class, simply import the class into your existing document class or other, and then create a variable instance. To call the formatter you will use “textfield.setTextFormat(variable.formatfunction);

The formatting class is below:

package com.riareviver{
 
//FLASH CLASS IMPORT
import flash.display.MovieClip;
import flash.events.*;
import flash.text.TextFormat;
 
public class TxtFormat extends MovieClip {
 
//VAR
public var myTextFormat:TextFormat = new TextFormat();
 
public function TxtFormat() {
//TEXT FORMATTER
myTextFormat.font = "Verdana";
myTextFormat.color = 0xFFFFFF;
myTextFormat.size = 10;
myTextFormat.align = "left";
}
}
}

Read more