Weblog Commenting and Trackback by HaloScan.com smspoonam@gmail.com: 06/01/06
|

Thursday, June 01, 2006

Date formatting/Date Validation

---------------------------------
datevalidate.mxml
----------------------------------







import mx.events.ValidationResultEvent;
private var vResult:ValidationResultEvent;

// Event handler to validate and format input.
private function Format():void
{
vResult = dateVal.validate();
if (vResult.type==ValidationResultEvent.VALID) {
formattedDate.text=dateFormatter.format(dob.text);
}

else {
formattedDate.text= "";
}
}
]]>






paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">








|

Setting up Eclipse for Flex

So you want to edit .mxml files in Eclipse, and don't want to pay for the oXygen plugin? No problem! This entry will show you how to configure Eclipse for Flex development the open-source way.

I've looked at a few of the XML plugins available (oXygen, XMLBuddy, etc) and from my own personal experience the best option that I've found for Flex development is the Eclipse Web Tools Platform.

The Web Tools Platform consists of two subprojects - j2ee and web standards. The web standards project includes editors for HTML, XML, CSS, etc. Because I'm a ColdFusion developer and don't do j2ee, I'm not interested in the j2ee subproject. By installing the web standards plugin from web tools, you can turn Eclipse in an .mxml editor, and as an added bonus get decent .css support as well.

I'll be showing more about this configuration during my From Flash to Flex talk next week, but for those of you who won't be able to attend and for those who plan on attending but want to jump ahead, here's how you can configure Eclipse for Flex.

1. Download Eclipse 3.1

2. Extract the .zip file to "install" it. I extracted mine to C:\Program Files (there is no setup wizard).

3. Download Web Tools 0.7. Important: You only want the Web Standards project if you don't plan on doing j2ee work. Also, you need to make sure you get all of the requirements (under the blue requirements header) or the plugin won't work. You'll want to get all of these files on the download page:

* emf-sdo-xsd-SDK-2.1.0.zip

* GEF-SDK-3.1.zip

* JEM-SDK-1.1.zip

* wtp-wst-0.7.zip (This is the web standards subproject)

4. Extract all of the .zip files to the directory where you extracted Eclipse to (again, mine was C:\Program Files). This installs all of the plugins.

5. Now that the appropriate plugins are installed, we need to configure Eclipse to recognize .mxml.

1. Start Eclipse

2. From the menu, select Window -> Preferences. Select General -> Content Types. On the right, expand Text and highlight XML. Click the "Add" button and enter "*.mxml" as the file type. Click OK.

3. Still in the Window -> Preferences menu, expand "Web and XML" and select "XML Catalog". Click "User Specified Entries" and click "Add" and use the following values.

* URI: browse for the path to the mxml.xsd file (something like: C:\Program Files\Macromedia\Flex\extras\schema\mxml.xsd)

* Key: http://www.macromedia.com/2003/mxml

4. Click OK to close the preferences window.

6. All that's left is create a Simple project, and add a new .mxml file. When you open it up, the XML plugin starts off in design view. Click the "source" tab on the bottom left of the content pane to go about your Flex coding as you normally would.

Whenever the web tools XML plugin sees the "http://www.macromedia.com/2003/mxml" namespace, you get full code hinting for both tags (like ) and attributes (like enabled="false"). It may not be an ideal solution (you don't get integrated ActionScript help), but it works pretty good and I've been having success with it.

Now, all you need to do is add a few templates to speed up workflow. The main templates I use are to set up an empty .mxml with mx:Application tags, and also a "sript block" tag to automatically create an mx:Script with CDATA. To edit your templates, go to Window -> Preferences and select "Web and XML" -> "XML Files" -> "XML Templates". The rest of the process should be pretty straightforward. Templates can be accessed via Control+Space (content assist - just look for the template name in the list).

|

Testing template update for flex2 beta 2

just changed
delete __instance;

to

__instance = null;

|

Creationpolicy behind the scenes

In flex 1.5 when i in mxml i assigned a component a model i did not care if that model existed or not. it failed silently and flex did what it did, bound correctly and the rest. the 8.5 runtime is not so forgiving, and i like binding my models in mxml. hence i had to start using creationpolicy differently than in the past. now i only create object when i need them and when i have all the necesary information. in the past we would only look at creationPolicy when the view was rendering too slow due too many displayobjects being rendered at once.

anyway. in flex 2 if you do this





then when you need the component you would do this

this.createComponentsFromDescriptors(true);

so whats happening in the background is the compiler creates code that looks something like this:


import mx.core.UIComponentDescriptor;

import org.lennel.descriptors.SomeComponent;

private function createSomeChildren():void

{

//I COULD NOT GET CUSTOM ARGUMENTS TO WORK

var args:Object = {};

var descriptor:UIComponentDescriptor = new UIComponentDescriptor(args);

// the object it will be attached to
descriptor.document = this;

//the class the descriptor is going to create for me

descriptor.type = org.lennel.descriptors.SomeComponent;

this.createComponentFromDescriptor(descriptor,true);



}



so if creation policy is set to auto all the descriptors are called at once, if Q'd in a Q, and well you should get the idea now. notice i use UIDescriptor.

|

Advantage of unit testing with flex2/AS3

An advantage of building your unit tests as you develop and tying these tests to some application entry point (a mx:Application tag for flex or a movieClip in a AS3 project) is that the eclipse editor uses incremental compilation to show your errors to you. thus developing something that exists in isolation and gets used nowhere won't give you proper feedback. having unit tests solves this problem nicely since every class you are writing has a test and every test is linked to the main test runner thus you can be garunteed that every peice of code you write is somehow imported and compilled.

|

viewstacks and states

a new feature of flex 2 is "view" states whereby i can layout multiple views on the same component using mxml (or actionscript) and change state by setting the currentState property on my view. you can also specify which transitions to use etc when switching from one state to another.
viewstacks in flex 1.5 (and 2) sortoff offer the same functionality.

in flex 1.5 some of the people who work with me tried to create 40 switcing icons that switched between 2 states.they quickly discovered this was a bad idea since all the movieclips got created at once, then the flex framework kicks in with its layout logic, so suddenly the time it took before the user could see a screen jumped from 1 second to 8 seconds. so the next approach was adjusting the creationPolicy, but this let them down an axis of evil (creationpolicy is not always as straightforward as expected). so what they did was create the clip in flex and use the embed directive. problem solved.
(this could have been done in flex 2 by creating a mxml component with 2 states.)

this example however highlights a limitation of viewstatcks in the past (i have not looked into the dynamics of viewstacks in flex2 so am not certain if all the views gets created immediatly but i suspect so) and maybe in the present. in contrast to this (view) states add and remove the clips as is needed. this is awsome in my opinion. also the zorn plugin for eclipse allows you to look at states independently when designing a form. its just been pointed out to me as well that the design view in zorn allows you to toggle between viewstacks as well

http://www.lennel.org/blog/2006/04/09/some-more-on-viewstacks-and-states/

|

Installing Flex Builder 2.0 on your Mac

I bought a PowerBook when i needed a laptop a while back. Although I’ve always used PC’s it made sense to get a Mac as it would give the the extra platform to test on.

So i’ve had been thinking about having a crack at installing Flex Builder 2.0 so I can mess with AS 3.0 on the Powerbook for a while. I’ve read a few threads about it being installed on a Mac but just avoided it cos i thought it could be such a hassle. Tonight i decided to give it a go my starting point Grant’s thread. So i was reading about installing flCompile and then read a few of the comments and found this posted by Carlington.

‘Hi!

It’s actually quite possible to use Eclipse + Zorn-plugin (Flex2) on OS X. What’s lacking is the mxml side of things in Flex2-projects, but Actionscript 3.0 projects work like a charm with breakpoints, runtime variable debugging, keywords etc.

Just get the zorn* files from the “features” and “plugins”-folders from the windows-installation and copy these to your Eclipse installation on OS X.

To sum things up:
1. Install Eclipse 3.1.1 on OS X
2. Install on Windows and copy the “zorn*” files from “features” and “plugins” to Eclipse-installation-folder on OS X, or alternatively get these from the plugin-installation zip-file. However make sure you unpack the *.jar files to folders.
3. Install mxmlc on your path, /Library/Flex2/ for instance.
4. Start new Actionscript project on OS X’

Well it works a treat. Just copy the files across from your PC and your ready to roll.

Wish I’d sorted that ages ago now!

|

E4X XML commands.

its a program that uses e4x format in xml and
event handlers to display the item.






import flash.events.*;
import mx.events.*;
import mx.controls.*;

private function changeEvt(event:Event):void {
forChange.text = event.target.selectedItem.@label;
}

private function nodeOpenEvt(event:TreeEvent):void {
forOpen.text = event.item.@label;
}
]]>



showRoot="false" labelField="@label"
itemOpen="nodeOpenEvt(event);" change= "changeEvt(event);">











verview#New_in_the_beta_3_release" />





























fontFamily="Times New Roman" color="#ffffff" alpha="0.0"/>

fontFamily="Times New Roman" color="#ffffff"/>


|

Itemrenderer concept

there is one more example with me,, which uses itemrenderer concept.
its great to work with,,
its nothing but a custom component class, which is said to be itemrenderer in tree concept.
in this program my datagrid uses itemrenderer component to acess the list data,

Item renderers do not impose restrictions on the types of Flex components that you can use in them. For example, you can use controls, such as the Label, LinkButton, Button, and Text controls to display data, but these controls do not let the user modify the contents of the control.

Or, you can use controls such as the CheckBox, ComboBox, and TextInput controls that both display data and let users interact with the control to modify or change it. For example, you could use a CheckBox control to display a selected (true value) or unselected (false value) cell in a DataGrid control.

When the user selects the cell of the DataGrid control that contains the CheckBox control, the user can interact with the control to change its state. To the user, it appears that the DataGrid control is editable.

However, an item renderer by default is not connected to the editing mechanism of the list control; it does not propagate changes to the list control's data provider, nor does it dispatch an event when the user modifies the cell. Although the list control appears to the user to be editable, it really is not.

main.mxml
---------------




[Bindable]
public var initDG:Array = [
{Contact: 'Rajesh', Company: 'Oinam',
Phone: '101', Project: 'Flex'},
{Contact: 'Mujesh', Company: 'Oinam',
Phone: '102', Project: 'Flex'},
{Contact: 'Ashok', Company: 'Oinam',
Phone: '103', Project: 'Flex'},
{Contact: 'Bose', Company: 'Oinam',
Phone: '104', Project: 'Flex'},
{Contact: 'Suraj', Company: 'Oinam',
Phone: '105', Project: 'Photoshop'} ];
]]>


variableRowHeight="true" width="464">

itemRenderer="RendererDGListData"/>
itemRenderer="RendererDGListData"/>
itemRenderer="RendererDGListData"/>
itemRenderer="RendererDGListData"/>



------------------------------

RendererDGListData.mxml
----------------------------------------

preinitialize ="init();">



import mx.controls.dataGridClasses.DataGridListData;
import flash.events.Event;

public function init():void
{
addEventListener("dataChange", handleDataChanged);
}

public function handleDataChanged(event:Event):void
{
// putting listData in datagrid
var myListDataataGridListData = DataGridListData(listData);

// Access data passed to the item renderer.
text="row : " + String(myListData.rowIndex) +
" column : " + String(myListData.columnIndex);
}
]]>


------------------------

|

Method not avaliable in Tree control in Flex2b3

Question:
i have one problem with Tree control in flex2.0 beta3 version i have already created my application in flex2.0 beta2 and now i am trying to migrate this code into beta3 ..in Beta2 tree control i have used one method say

getNodeDisplayedAt(0) to retrive perticular node from Tree control now in beta3 they have not provided this method....
Answer:

its getChildAt(0) or can also use getChildByName

|

about the Flex and Flash

I have long thought that if the purpose of the RIA movement is to create
desktop like apps that run in your browser...

Flex and Flash in terms of
1. Performance

2.Loading time

3.Quality

4.Look and feel

5.time consuming


If Flash can be used for e-learning (as we do), what would make it so
incredible to believe that Flex could also? I find e-learning to be
well-suited to forms-style development, particularly if you throw in
some script-driven animation. Seems to me Flex is probably better
suited to this kind of work than Flash is.
========================
I think flex is more adequate to create RIA.
- You have more components in flex than flash
- I don't think that flash has layout components.
- if you plan to use charts flex has charts api (bargraph,pie,...)
- coding is more easy in flex, you don't have to set some piece of code into multiple frames.
========================
Well if you plan to use out of the box components w/ little customization , then I would agree with FredFlex, however if you are going to need to make custom components and those components will be the bulk of the structure of your RIA, then I would think long and hard about a few things:

- the poor documentation of Flex vs the established and growing documentation provided by MM and a huge user community
- the target audience in terms of FP8 or earlier vs FP8.5 and FP9.
- how much of this RIA will rely on web services for data retrieval/sending
========================
- FP9 has a low audience and I encounter problems to install it (need to manualy uninstall FP8)
- Flex is in Beta version! We don't know yet if adobe will support it efficiently
- for the documentation you can see the exemples (somes with source code) on labs.adobe.com
- you can use free AMFPHP (http://www.amfphp.org/) if you need to use remote services, there are very good videos tutorials
========================
Someone suggested that Adobe hasn't done a good job explaining the
difference between the two. I can't see how you can say that. There
has been a public beta available for over 6 months and a site almost
entirely devoted to it. The Samples Explorer is as clear an
explanation as any developer should need. The only way to really understand the difference is to attempt to build something with it.

While I think the concept of a beta program is great, I spent quite a
few hours poring over the documentation, and followed a few tutorials, and
I did not find the clear explanations I was hoping for. Maybe that makes me
a bad developer. But I assume Adobe wants to sell to bad developers as well
as good ones. This was a few months ago, so maybe things have
improved.

If I'm wrong, please point me to the documentation, FAQs, etc. from
Adobe that clearly explain the diferences between Flex IDE and Flash IDE, or
details about how to integrate Flex into my workflow. Maybe this is
all coming after the release. Or maybe it's been added since I looked
through the labs site. Where is the practical tutorial for Flash Developers
who want to transition to Flex?

I want to like Flex. I really do. I'm not trying to attack any Flex
developers or any of the smart people who work at Macromedia/Adobe.
I' m just sharing my personal observations around it so far. There's
enough contradictory info in this thread alone to make me think they're not
doing a good enough job getting the message out. The ongoing success of Flash is important to me personally, and to my career, so I that's why I've felt
the need to say this.

i also don't think it's a question good developer vs bad developer. The
Flex metaphor was developed to be comfortable to developers coming from a
non-Flash background. Most of us were attracted to Flash exactly
because it wasn't like those environments. I think you're correct in
saying that the existing documentation is written with non-Flash users
in mind. Consequently a lot of Flash users may take a while to "get
it". I'm still struggling with some of the details. But I'm finding
more and more situations where I'm asking myself ; "is it really that
easy". But it's taken me quite a few hours to get to that point.

|

Using XML Namespaces with E4X and ActionScript 3

Here is a simple example demonstrating how to use namespaces to access element nodes using E4X syntax. Create a new Flex Project and paste the code in the main .mxml file:
---------------------
main.mxml
---------------------

layout="vertical"
creationComplete="onCreationComplete();">

showBusyCursor="true" resultFormat="e4x" result="onResult( event );" />



import mx.rpc.events.ResultEvent;

[Bindable]
public var rockArtists:XMLList;

// Define the namespace used in the rss feed for "itms". Note that the
// namespace we define is "items" instead. These values do not need
// to be the same, but generally should be for readability purposes.
namespace items = "http://phobos.apple.com/rss/1.0/modules/itms/";

private function onCreationComplete():void {
// Load the RSS feed
latest.send();
}

private function onResult( event:ResultEvent ):void {
var rss:XML = event.result as XML;

// Filter the feed by the Rock category
var rock:XMLList = rss.channel.item.(category == "Rock");

// Use "items" namespace prefix (corresponding to the namespace we
// defined above) to access the artist elements
//rockArtists = rock.items::artist;
// Or, alternatively:
use namespace items;
rockArtists = rock.artist;
}

]]>






---------------------------------------

The above code will grab the 10 New Releases from iTunes, filter the results by the Rock category, and display all of the artist names inside of a List.

The key here is that the artist element nodes are created with in the RSS feed. In the XML, the "itms" namespace is defined as xmlns:itms="http://phobos.apple.com/rss/1.0/modules/itms/". This namespace is re-created in ActionScript using the namespace keyword in ActionScript, but instead of calling it "itms" it is defined as "items". In general, you'd want to keep the prefix the same for both, but for illustration purposes you can see that they're allowed to be different.

Accessing the artist element nodes then is simply a matter of using the namespace via use namespace items and asking for just the artist (without the namespace prefix). Another approach is to omit the use namespace ... code and use the namespace prefix directly: rock.items::artist. In both cases, the namespace to use is the one defined in ActionScript, and not the one defined in the XML file (so "items" instead of "itms").

|

Loading external data at compile-time

Sometimes it's useful to load data into your application from a file, without having to load it at runtime. If you need to do that, here's how.

[Embed(source="data.xml", mimeType="application/octet-stream")]
private static const MyData:Class;

private function init():void{
var ba:ByteArray = new MyData() as ByteArray;
var myString:String = ba.readUTFBytes(ba.length);
trace(myString);
}

It would be nice if you could set the content type to text/plain or text/xml, and get something a bit less raw than a ByteArray, but it's still nice that we can do this.

Since the data is available from compile-time, you can even use it as the value for a constant:

[Embed(source="data.txt",mimeType="application/octet-stream")]
private static const MyData:Class;

public static const MY_CONST:String = setConst();

private static function setConst():String{
var ba:ByteArray = new MyData() as ByteArray;
return ba.readUTFBytes(ba.length);
}