Flex Builder

May 21, 2008

SVN Checkin Madness

I had the follwing problem while checking in files to google code with the subversion for eclipse.

Svnerror

It was rather frustrating. Working on it for about 20 minutes. Cleaning stuff out of SVN repository and trying to update and and synchronize I remembered my SVN goto. Simply find your .svn file in the folder you’re having problems with and then delete it > then just add them back to source control.

Svnerror2

May 20, 2008

Austin Flex User Group

I’m going to be giving a presentation this Wednesday, 5/21/2008, via Connect to the Austin Flex User Group. It will actually be two presentations. The first is a session on debugging from within Flex Builder. I’m going to focus on debugging techniques and also will explore remote debugging with ColdFusion, C# and Java. The second session will be a sneak peak on how you can leverage cloud services with a flex front end using the Smashed Apples framework, but specifically I’m going to be talking about Amazon Web Services and how you can leverage cloud services to make money. That’s always fun!

You can find out more info at: http://www.austinflex.org/.

If you’re in Austin, Texas I hope you can make it.

May 15, 2008

Overloaded Methods in Action Script ( sorta )

via wikipedia

Method overloading is a feature found in various programming languages such as Ada, C#, C++ and Java that allows the creation of several functions with the same name which differ from each other in terms of the type of the input and the type of the output of the function.

I’ve wanted overloaded methods in Action Script for some time now. After using it in other languages like java and c# it’s really easy to train your mind to solve one off scenarios with overloaded methods. Much more than an easy way to provide defaults for lots of different scenarios I enjoy crafting them to manipulate program behavior for base or core classes so that the actual implementation of the program becomes much more simple and easier to maintain.

I’ve tried several approaches to getting something similar and elegant in Action Script. Most everything came down to being a hack and turned out to be more work than was necessary to implement. I know overloading is more of an AS thing than an FB thing but thinking about new FB4 features  – (my comment is still awaiting approval as of this writing, I mentioned visual studio’s intellisense, oops) the other day made me decide to sit down and attempt overloaded methods one more time. This time I wanted to look at my prominent use cases and see if there was a way to solve this issue.

The two use cases I came across time and time again were 1) eventHandler methods that accept related and similar events: breaking them out to thier own function is do-able but is a lot of work when the difference of how you handle them is 1–off. And 2) methods that take a UIComponent of some sort that either gets or sets data. For example, if you were to loop over an array of form input controls reading / writing data to them you’d find the difference in how you set or get data on them is very similar but just a little different. A TextInput just reads and writes to the “text” property. A ComboBox might read and write to a selectedItem[”property”] value. Or you might want to pull the htmlText value off the RTE.

With those use cases in mind, I thought about how I could handle the two problems simply and elegantly, not necessarily by overloaded methods but just something that could slim my code down, drop a lot of casting, and at the very least make my code more maintainable and more precise in it’s intent.

The first obvious thing I saw was that I didn’t need to worry about the number of arguments, although the technique I’m gonna demonstrate can be used with multiple parameters or event the …rest params. In my case I’m handling an event or a view in both cases. The second thing I saw was that I’d almost solved this problem. In most of these methods I was just accepting either an Event or UIComponent or something similar. The next thing I noticed was that I was either casting from within switches or if statements and I was executing my computing goal from within my function or calling an outside function to accomplish something. With that in mind I decided calling an outside function was the best method. Indeed, once you identify what you want to do, with overloaded methods you can easily add more methods with different signatures that all call your most basic function. The names on all the methods are all the same. Your code becomes very clear in it’s intent. It’s not saveEmployee(), saveUser(), it just becomes save(user), save(employee).  It’s important to note that I understand the former examples are very intent. However, the latter examples, when working in teams or groups, it’s much easier to learn and remember save(variable) and when you want to save an object and you don’t know if it’s an Employee or User you don’t have to worry about it because in most languages the compiler creates your switch or if statements for you.

 ( you should be able to see the next step with overloaded methods, which is to dynamically interpret objects you didn’t know about save(order), save(product) for example. Ruby on Rails made this kind of processing retro the past few years, but I’ve been doing something similar with coldfusion argumentCollection for years now. Check out Proxy if you’re interested in that. )

So to get to the demo, I created two functions with the same name eventHandler(), eventHandler(). My first method is my bucket. It’s where I want to throw everything into. My second method is my target method, the method that does the cool kick ass thing I want it to. It takes very specific arguments. Obviously it didn’t compile. So I created a namespace in the default package ( so I don’t have to import it ) called overload. I made my first method public and put my second method in the overload namespace. I reworked how I called the overload method and it compiled. To interpret my arguments I use a switch statement or if statements depending, like i was before. My code then becomes very intent. It at least accomplishes my goals with overloaded methods.

Overloadcode

 

A couple thoughts on this technique. First, I looked for but didn’t find that overload was a future reserved word in ActionScript. It feels like something that might be. Secondly, ActionScript should define overloaded methods, the compiler should implement them and and FB should support them.

Here’s the live demo. Right click for source.

 

 

 

 

 

 

 

April 16, 2008

Global classes and static global functions sans import

Global Classes

To define a global class simply create your class at the root of your project within the default package as follows:

package

{

public class MySweetNewType

{

}

}

 

 

No more importing. Although this is discouraged by flex builder there are some very legitimate reasons why you might want to have a global class defined that is automatically imported into everything. Utility classes, user classes, permission classes, custom data types are some that come to mind. My rule of thumb on this is that the frequency of use justifies the means. If I find I'm using a class over and over again and I have to constantly import it, I put it in the default package and refactor.

But if you’re using a class over and over again, it’s time to think about a reusable Library. Just drop your class at the root of your library and reference the project and it works without importing as well.

 

Global Function

You can’t define a global function that rests at the root of the package and automatically gets imported (that works, it shows up in code hinting tho). But you can define a class with a static function that gets you close enough. If you get creative with your class name ( remember class name and file name have to be the same ) you can get close enough to a global function as is necessary. An example is below. this allows you to call echo with the simple syntax of $.echo(‘hello’). This works good for functions you find very repetitive. Using the dollar sign as my class name makes it very apparent that it’s not just any old function. I’m not sure if this has any side effects so if anyone knows or finds out let me know. So far it’ has passed the smell test.

 

package

{

public class $

{

public static function echo(phrase:String):String

{

trace(phrase);

return phrase;

}

}

}

 

 

 

 

 

 

 

April 14, 2008

Me to Flex Builder Additional Compiler Arguments: "UR Dumped"

I’ve never been dumped via text message but I hear it’s en vogue these days. If it happened to KFed I guess it could happen to anyone. So don’t be so surprised when I say I gotta give the boot (If i knew who to text about this I would) to the Flex Builder Additional Compiler Arguments. I will no longer waste my time fiddling around with a growing list of compiler options that runs off my screen and

Compilerotpions

makes me wanna pull my hair out. I really only have about a quarter of my compiler options visible in the image above. So I’m moving on to a flex-config.xml file. It offers easier readability ( who doesn’t like easy). There’s an example that comes with the SDK and best of all I can now use the same config file in Flex Builder as I do in my automated Build Process. ( We use Microsoft build btw ). Isn’t that nifty. There’s some other great benefits to this as well. If you’re sharing projects and using custom meta data or other custom compiler options and you are not checking in your .actionScriptProperties and .flexProperties files (because you all don’t have the exact same system configuration), just Check the flex-config.xml file in with your code and then your developers now only have to remember one command line option as stated below:

Compilerotpions2

( so fresh and so clean )

Simplify your ANT builds as well. Instead of having alot of <args> you can just use one.  -load-config. You get the same build in ANT as you did in Flex Builder. Also, you’re not limited to an all or nothing load-config=flex-config.xml file. If you change the = to a += you get the options in Flex Builder Plus whatever you define in your config file. So you can have yer cake and eat it too. The syntax for customized config files follows the same pattern as the flex-config.xml file. So you can use it as a template to get started or use it as a reference as you go.

This was a dumping that was a long time in the making. I need more granular control of my projects.

 

 

 

 

 

 

 

Every little -as3 namespace bit helps ... I think

While trying to eke out every little last bit of performance in my flex app I ran across the -as3 compiler option. The LiveDocs state

Defines methods and properties of the core ActionScript classes that are fixed properties instead of prototype properties. When you set the "-as3" compiler option to true, the AS3 namespace is automatically opened for all the core classes. This means that an instance of a core class will use fixed properties and methods instead of the versions of those same properties and methods that are attached to the class's prototype object. The use of fixed properties usually provides better performance, but at the cost of backward compatibility with the ECMAScript edition 3 language specification (ECMA-262). 

I added it to my app, and ran some profiling. Not sure what to look for. If you have experience using it feel free to chime in now. Otherwise I guess I'll get back to trying to out-fox myself  doing nothing because there is no more hope.

 

— UPDATE : hat tip to josh for pointing this out. The -as3 compiler is automatically turned on. You’re supposed to use the -es compiler option if you do turn it off. Here’s a current link to the livedocs that gives more info.

 

 

 

 

 

April 10, 2008

Getting Started on Google App Engine with Flex and PyAMF (2)

UPDATE: For setting up PyAMF I recommend using this article written over on PyAMF. This original post was written before a patch was created. And there instructions will be more up to date and maintained.

 

The previous article on this topic can be found here.

I’m also shamelessy pulling from this article. It almost got me there, but there was one thing noted below that I needed to do. 

1. Download pyamf.

2. Now unzip the pyamf into a directory ( i went with c:/pyamf ) and browse to it from the command prompt. When you get to the source folder run “ez_setup.py”.

3. Now complete the following steps ( original reference can be found here )

  • Download and unpack pyAMF-0.2
  • Download fpconst and put it in pyAMF-0.2/pyamf
  • Delete the file pyAMF-0.2/pyamf/adapters/__init__.py
  • Comment out the line register_adapters(); at the end of pyAMF-0.2/pyamf/__init__.py

 (I did these steps and found I still needed to comment out line 26 in the pyAMF-0.2/pyamf/__init__.py that looks like:  from pyamf.adapters import register_adapters )

4. After that is completed, go back to your command prompt and run “setup.py install”

5. Afterwards in the directory where you downloaded pyamf you should have a directory that has a dist directory under that. Add the .egg in the dist directory to your System – PYTHONPATH. in windows > prefs > PyDev > Interepretor just like we did for the google.zip file above. ( This will bring in code completion support )

6. From the command prompt start your server   /appengine/dev_appserver.py {app name}

7. Browse to http://localhost:8080/

if everything’s set up and running properly you’ll see something like

400 Bad Request

To access this PyAMF gateway you must use POST requests (GET received)


 


 


8. Finally, create a flex app.  Below is the code I used. You should be able to drop it in your flex app file. If everything works you can use the appcfg.py commands to upload your application and point your endpoint to your new application url.  


Pyamfcode1


 


This is by no means complete and I hope to get more examples up and running soon. If you have any questions feel free to comment or email me. I’ll be posting on how to debug python apps from eclipse when making calls from flex and also some other topics that have been floating around. Like Google Authentication.


 


 


 


 


 


 



 

April 09, 2008

Getting Started on Google App Engine with Flex and PyAMF (1)

So this is my first of hopefully two posts on getting setup to work on Google App Engine. This will get your python and local google server up and running

1. Download and install python if you need to.

2. Download and install the google app engine sdk. I recommend installing this somewhere on your system that is easily accessible. By default on windows it went under /program files/google/appengine. I reinstalled it under c:/appengine/ for easy access from the command prompt. Do as you will but remember where it gets put.

3. Install pydev into your eclipse. There’s a great getting started guide for pydev located here. It explains how to set your python interpreter up.  

To add code complete support for the google sdk in eclipse first zip up the google directory in your appengine installation directory. Then go to windows > prefs > PyDev > Interpretor : System PYTHONPATH click “New Egg/Zip” and add that google.zip

UPDATE: The crossed out steps are better explained by this post  about getting your debugger up and running in eclipse.

4. Create a new PyDev project. Finish. 

5. Now browse to your appengine installation directory and copy / paste the new_project_template into the same directory. Then rename it to the name of  your project.

6. And now back in eclipse right click on the src folder and do a add new folder > advanced > Link to the file system and browse to the project folder under your appengine installation.

7. Open app.yaml on the top line change the application: new-project-template to application : your-app-name

 

Now open a command prompt and go to your appengine isntallation directory and type dev_appserver.py —port=9999 {YOUR APP FOLDER NAME}

Then open a browser and go to http://localhost:9999/ and you should see it running.

 

Installing PyAMF and Setting up flex environment next.

 

 

 

 

April 04, 2008

My Open Source Flex SDK Experience

I’ve been trying to get setup with the Flex SDK for some time now. I’d like to investigate the inner workings and learn as much as I can about flex. Well, now it’s Friday afternoon and I’m a bit tired. It’s sunny outside and i should be on the river or in the hammock but I haven’t been able to get a build off the Flex SDK, and I’m getting to that point. I feel like I’ve followed all the directions to the best of my ability and I just haven’t been able to get it done. You know where I’m at, we’ve all been there. I’d just like to make the suggestion that being able to check out just the flex framework would be an awesome way to get lots of flex developers quickly involved. Having to check out the entire flex project is a bit daunting.

Yeah, yeah, I know, be careful for what you wish for. Anyways, since it is friday, the following is my experience with getting setup with the Flex SDK.

Borat-flex-sdk 

March 11, 2008

The View From My Screen

InternalError

 

Fort Collins, Co. 11:13 AM