Archive for the ‘Code Example’ Category

Command line goodies

Wednesday, July 8th, 2009

Here are some command line tidbits that i use regularly and find to be very handy, hopefully you will too.

Create a list of files in a directory and all its subdirectories
find [path] -type f > [output file]
example for listing all files in the directory source:
find source -type f > files.txt

Monitor cpu usage
top -F -ocpu -s 5 -n 5

Update Modification Date Recursively
find {dir} -exec touch {} \;

backup a directory
rsync -av –delete [src] [dest]

search through your command line history
history | grep -i “search string”
this will output a list of history commands by history number that match your search, then use the history number to run that command again
![history number]

remove all .svn directories
find ./ -name “.svn” | xargs rm -Rf

Embedding fonts in an ActionScript Project

Thursday, June 18th, 2009

Working with ActionScript projects can offer some rather interesting challenges with some of the most basic parts of Flash development. Things like preloading your application and using linked MovieClips from a library, not to mention using embedded fonts in your TextFields. This really becomes interesting when you want to use more than one font in a single TextField. And sure you can embed font files right into the AS class, but that doesn’t always work. I’ve had numerous issues with OTF fonts.

The method that I have had the best success with is using the same technique as embedding symbols from Flash AS2 swfs. Here’s a step-by-step on how to do this.
(more…)

Recording and streaming video with FMS, Flex and AS3

Thursday, May 21st, 2009

For some reason all of the code examples for using FMS are in AS2. Converting the examples to AS3 can be a bit challenging, especially since there is one really key piece of information that is left out that is new to AS3 and specific to the use of FMS2. The problem is the that FMS2 only supports AMF0, but in AS3 the default setting for the NetConnection class’ defaultObjectEncoding property is AMF3. Without changing this setting to AMF0, your code will seem to be correct, but will fail to connect without really telling you why. Check out the class that I created from the Adobe example and the MXML to use it.
(more…)

Dispatching events between AS3 and AS2

Saturday, May 9th, 2009

Even though AS3 has been out for some time now, there are still situations when you will need to load an AS2 compiled SWF into an AS3 compiled SWF and communicate with it. What if you could simply dispatch an event and listen for it on the other side? That’s what sugarcookie’s ASBridge does. Let’s see how it all works.
(more…)

The problem with dropTarget

Friday, April 17th, 2009

While working on an application that has some drag and drop functionality, I noticed something very interesting about the dropTarget property of the Sprite class. It seems that the dropTarget returns the DisplayObject that is at the bottom of the display list which may not yield the result you are expecting. I added a MouseEvent.MOUSE_MOVE event listener to the Sprite being dragged and traced out the dropTarget to see what kind of result I would get.
(more…)

Trace statements for PHP

Wednesday, March 11th, 2009

If you’re a Flash developer then you probably use trace() as an essential part of your development routine. Maybe you even wrote a custom logger application to get a peak into what’s happening with your Flash application. Point is that you like to see what’s going on behind the scenes.

Now you’ve moved on to the big leagues and started connecting Flash to PHP to add server-side functionality to your application, but how do you see what’s happening with your PHP code? PHP has a little know feature called error_log() that lets you output messages to your web server’s log file. By tailing your log files while running your application you essentially get trace statements from your PHP code! You can do this by opening your terminal if on a Mac or use something like cygwin on Windows, change directories to where the log files are and run the tail command with the follow flag.

Welcome to Darwin!
colossus:~ chris$ cd /var/log/httpd/
colossus:/var/log/httpd chris$ tail -f error_log
[Tue Jun  5 22:31:11 2007] [error] This is my trace statement from PHP!

Enjoy and happy PHP testing!

Creating a custom logging target

Tuesday, March 3rd, 2009

I figured since I’m on the subject I would go ahead and create a custom logging target for sugarcookie and a companion logging app – LumberJack. This particular target sends log message objects over a LocalConnection to a basic logging console that will output them into a text field. Being able to see trace statements from a site running on any server, on any network can really help when debugging your application that is deployed somewhere besides your localhost. There are other tools out there that do this like RED|Bug, Xray or even FlashTracer, but this one is extremely simple and includes all the code so you can modify it to suit your needs.

First let’s create the new log target class by extending the existing mx.logging.targets.LineFormattedTarget Flex class. Then override the logEvent method with the functionality desired and you’re in business. Here’s how I did it:
(more…)

Removing trace() statements from Flex applications

Thursday, February 26th, 2009

Removing trace() from your code is a great way to optimize it and improve overall performance. This is easy enough to do in Flash by checking “Omit trace actions” in the Publish Settings window, but in Flex there is no such setting or compiler argument that I’ve seen. No worries, there is a solution.
(more…)

Mounting Windows shares on Linux

Wednesday, February 11th, 2009

Recently I had the need to back up my svn repositories root directory that lives on our Linux dev server to a Windows server. At first I tried to mount an NFS Windows share to my Linux box, but because we don’t have an NIS server I am not able to authenticate my Linux account against my Windows account. Most of you developers out there that have to support yourselves will probably have this issue because most office IT infrastructures are Windows based which don’t always play nice with your Linux dev box. The answer to this wasn’t as straight forward as you might think, so I thought that I would share my solution.
(more…)

Flex and Flash play nice with DisplayObjectWrapper

Friday, December 12th, 2008

If you’re a Flash developer making the switch to start using Flex, then this class from Grant Skinner is for you. DisplayObjectWrapper makes life much easier by enabling developers to easily get anything that inherits from DisplayObject (Sprite, Loader and Bitmap to name a few) to become a display child of a Flex container (Canvas, ViewStack, Accordion, etc). Awesome, now here are some code examples of how to work with SWFs in Flex.

This mxml code example shows how to:
- load a Flash 9/10 SWF
- call a method within the document class of the SWF
- receive an event from the loaded SWF
(more…)