YOUR FEEDBACK
Simplifying Data Center Management
Sashi wrote: They still owe me a large sum of money!!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
MXDJ TOP LINKS YOU MUST CLICK ON !


MXML vs ActionScript 3
Building custom AS3 components

Digg This!

I've been building a bunch of custom AS3 components for clients lately, and have run across the need to use view states within an AS3 component.

Working with states in MXML is pretty trivial, using the AddChild, RemoveChild and SetProperty tags, you can do virtually anything you need, but when working in an AS3 only environment, it becomes a bit trickier, since there are no tags. Of course, anyone who has worked with Flex for any length of time knows that MXML tags are interpreted into AS classes before the application is compiled into a SWF, so anything you can do in a tag, you can also do with pure AS.

I was looking to do the AS3 equivalent of this:

<mx:states>

    <mx:State name="minimized">

       <mx:SetProperty target="{this}" property="height" value="{this.getStyle('headerHeight')+15)}"/>

       <mx:SetProperty target="{this}" property="width" value="{this.minWidth}"/>

       <mx:SetProperty target="{this}" property="vScrollPolicy" value="off"/>

       <mx:SetProperty target="{this}" property="hScrollPolicy" value="off"/>

    </mx:State>

</mx:states>

Here is my AS3 to do the same thing:

private function buildStates():void{
    var overrides:Array = new Array();
    var newState:State = new State();
    overrides.push(makeSetProp(this,"height",this.getStyle("headerHeight")+5));
    overrides.push(makeSetProp(this,"width",this.minWidth));
    overrides.push(makeSetProp(this,"vScrollPolicy","off"));
    overrides.push(makeSetProp(this,"hScrollPolicy","off"));
    newState.name="minimized";
    newState.overrides = overrides;
    this.states = new Array(newState);
}
private function makeSetProp(target:UIComponent, property:String, value:*):SetProperty{
    var sp:SetProperty = new SetProperty();
    sp.target = target;
    sp.property = property;
    sp.value = value;
    return sp;
}

Essentially what we have is that each UIComponent has a property called states, which holds an array mx.states.State instances. Each State has an array of things to override, called "overrides." In this case, each of the overrides is a SetProperty, although, it could just as easily be AddChild or RemoveChild.

About Jeff Tapper
Jeff Tapper, co-founder of Tapper, Nimer and Associates, is an Editorial Board member of Web Developer's & Designer's Journal. He has been developing Internet-based applications since 1995, for a myriad of clients including Toys R Us, IBM, Allaire, Dow Jones, American Express, M&T Bank, Verizon, Allied Office Supplies, and many others. As an Instructor, he is certified to teach all of Adobe's courses on Flex, ColdFusion and Flash development. He has worked as author and technical editor for several books on technologies including Flex, Flash and ColdFusion, such as "Object Oriented Programming with ActionScript 2.0", and "Flex 2 Training from the Source."

LATEST FLEX STORIES & POSTS
AJAX World - Skyway Software Announces RIA Developer Contest
According to Sean Walsh, President and CEO of Skyway Software, 'Our Skyway Community is thriving and our members are very talented. We truly look forward to their RIAs submittals and Skyway Builder extensions and are excited that all of the contributions will benefit the entire Skyway
"Virtualization Journal" Debuts This Week at JavaOne
Founded in 2006, SYS-CON Media's 'Virtualization Journal' is the world's first magazine devoted exclusively to what Gartner has earmarked as the single highest-impact IT trend through 2012: virtualization. And now it will be available on newsstands worldwide, as SYS-CON Media seeks to
3rd International Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
Microsoft To Keynote 4th International Virtualization Conference & Expo
Mike Neil is general manager for virtualization strategy in the Windows Server Division at Microsoft. Mike is focused on the delivery of the Windows virtualization technology, including Windows Server 2008 Hyper-V, Microsoft Hyper-V Server and Virtual PC 2007. Mike also directs the tec
Wal-Mart To Sell $399 Ubuntu Linux-based Laptop with Google Operating System
The Ubuntu Linux-based gOS operating system from Good OS LLC (www.thinkgos.com) includes so many Google applications like Gmail, Google Docs, Google Calendar, Google News Google Maps and YouTube that it's often referred to as the Google operating system. It also includes Firefox, Skype
Flex 4: My Wish List
Flex 2 was released in the Summer of 2006 and it was a mini-revolution in the RIA space. Almost nobody knew about Flex 1.5, but now almost everyone has at least heard about this software. Flex 3 was released in early 2008. It has a number of useful new features, but it was not a major
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE