Monthly Archives: November 2004

Fun with Intervals

There are several tricks to working with Intervals that makes them easy to manage and change.&

The ids for intervals are numbers globally in the player. When you create an interval with setInterval, it returns a unique id for the interval you set starting with 1 and iterating higher.

myInterval = setInterval(function(){trace(‘I1’)},100)

trace(myInterval) //1

myInterval = setInterval(function(){trace(‘I2’)},100)

trace(myInterval) //2

myInterval = setInterval(function(){trace(‘I3’)},100)

trace(myInterval) //3

//clearing the intervals you have set it even easier.




Another interesting patterns is creating a generic Interval function that you can add functions into. The following function will attempt to execute every object stored within the function.

intervalCore = function(){

var self = arguments.callee

for( var x in self) self[x]()


myInterval = setInterval(intervalCore,100) = function(){trace(‘one’)}

intervalCore.two = function(){trace(‘two’)}

intervalCore.three = function(){trace(‘three’)}

//delete the items in the interval:


delete intervalCore.two

delete intervalCore.three

Or if you simply want to clear out all the Intervals within the Flash Player:

i = setInterval(function(){},100) + 1






Proxy Class for Flash

Proxies are a handy concept in any programming language but I have found them especially useful in Flash when dealing with references.&

Proxy Class example:

First a little primer on references in Flash:

There are essentially 3 types of references in Flash:

Primitives –> A = 3

Objects –> B = [1,2,3]

MovieClips –> C = _level0

In the above code, A, B, C are all references to data in memory. The Flash Player stores the data assigned to references in a pool of memory maintained by the Flash Player garbage collector. As long as a reference exists to memory, the garbage collector will not recycle the memory allocated. When you use ‘delete’ on a reference the reference is deleted not the target memory.

When you assign a second reference to an existing reference, the value of the reference is assigned to the new reference. Depending on what type of reference is assigned different things happen as follows:

Primitives: Primitives are assigned by value. When they are assigned,it is identical to creating a new reference and assigning value and type.

// create reference A

// assign value of 3

// assign type Number

A = 3

// create reference AA

// assign value of 3

// assign type Number

AA = A

Objects: Objects are assigned by reference

// create reference B to a new space in player memory

// create an array in the player memory assigned to B

B = [1,2,3]

// create reference BB and assign it to the memory allocated to B

BB = B

MovieClips: MovieClips are assigned by reference to a unique depth (slot)

// create reference B to the MovieClip assigned to _level0 (unique by depth!)

C = _level0

// create reference CC and assign it to the memory allocated to C

CC = C


So now onto Proxy. A proxy is different as it is an object that actually points to another object. When references are assigned to a proxy, they are assigned to the proxy not the target object. If the object behind the proxy changes, the existing reference points to the new value. Normally, older references remain glued to the older value as follows:

//create a new array

A = [1,2,3]

//create a reference to A

B = A

//create a new array

A = [20,30,40]

trace(B[0]) //1

trace(A[0]) //20

When A was overwritten with a new value, the B reference maintained the link to memory originally allocated to A.

Let use a Proxy:

//create a Proxy with a value of [1,2,3]

A = new Proxy( [1,2,3] )

//create a reference to the Proxy

B = A

//trace the value through the proxy references

trace(A[0]) //1

trace(B[0]) //1

// change the Proxy value

Proxy.setValue( A , {name:23} )

//trace the value through the proxy references

trace( A[‘name’] ) //23

trace( B[‘name’] ) //23

//obtain the true Proxy value

myProxyValue = Proxy.getValue( A )

The proxy allows you to create references that change with the value assigned prior. They are very unique and provide a powerful programming concept in Flash. In other languages ( Java, C#, Python ) Proxy types allow you to control the Proxy instance interface and restrict usage in unique ways. A Proxy is a very clean way to provide mix-in classes, remoting, and essentially hide implementation details in larger scale application development.

There are several serious problems with this implementation of a Proxy:

1. Performance – Proxy uses __resolve to provide proxy behavior. Every time the proxy is used the __resolve method is fired within the Proxy Class. This is performance intensive and widespread use of this Proxy class would be sure to create performance problems in an application.

2. Semi-Transparent – It is fairly easy to see that you are dealing with a Proxy instance. Ideally proxies instances are seamless and you cannot tell them from the real data object. In the above case, a simple trace on the Proxy itself will show the facade presented. Also since the Proxy uses __resolve, the proxy interface is distorted as it will always include this extra method.

3. Activation Object – Since __resolve needs to be unique for each Proxy instance, a function was assigned in the Class constructor thus binding the Activation Object into the Proxy Instance. There is not other way to get Proxy behavior without triggering this issue.

4. No Primitive Support – It is difficult to proxy primitive values as they are passed by value not by reference. Accessing the primitive value forces the use of the valueOf method and can cause problems.

I would like to see a native proxy class for Flash 8 that resolved the above issues and extended the capability for using Proxy types in this manner. A native extensible Proxy class would allow us to define new proxy functionality and create patterns within Flash that make software development much cleaner and seamless.

If you would like to see a native Proxy Class in Flash 8, please add a comment to this Blog entry. Hopefully with community support and discussion, we might see this jewel added into the new Flash 8 Player.



MovieClip Class getDepth replacement

When you are working with MovieClip depth, I have found this getDepth replacement method invaluable. It allows you to obtain depth information about children through the getDepth method when called on a parent MovieClip.&

GetDepth Example

First a little code as an example:

//get a reference to the child MovieClip on “top”

myTopRef = _level0.getDepth(‘top’).ref

//get a reference to the child MovieClip on “bottom”

myBotRef = myTopRef = _level0.getDepth(‘bottom’).ref

//get information on all child MovieClips

myDepthData = _level0.getDepth(‘all’)

The method provides backward compatibility so it will not effect your existing movies that depend on getDepth. It works well with V1 and V2 components and lets you see what really exists within a MovieClip.

One of the dilemmas in working with MovieClips is that you can’t assume that references are child MovieClips, they might point to another timeline in the player. This method used the sort order of the for .. in loop to sort between the two.

The getDepths replacement returns an object for each MovieClip. When you use ‘top’ or ‘bottom’, you will get a single object like so:

{depth:23, name:bob, ref:_level0.bob}

When you use ‘all’ you will get an array that contains all the child MovieClip objects within a parent MovieClip and references within the parent will be excluded. Here is a sample of what is returned:

[{depth:23, name:one,},{depth:24, name:two, ref:_level0.two},{depth:25, name:three, ref:_level0.three}]



1000 installs of XTreeM in 20 days

The XTreeM XML editor passed 1000 installs late Saturday evening. I wanted to take a moment and answer some frequently asked questions.&

What is XTreeM?

It is an XML Editor based on a Tree. When you load XML into XTreeM the tree provides a visual representation of the XML hierarchy. You can edit the XML document directly by dragging and dropping nodes on the tree. When you edit XML in this manner all edits will preserve the validity of the xml. Attempting to do the same thing in a plain text editor is prone to error.

How do I add an XML Node?

1. Create a new XML Document by pressing .

2. Select the XML Node named “newXML”

3. Press any of the XML Node buttons just above the tree.

When you add XML Nodes the new node is automatically selected. If the added node does not support certain types of child nodes, the menu will disable the unsupported nodes. In most cases you can only add XMLNodes into Elements.

Define the XML Node Icons

Starting left to right:

Add Element (similar to the Xtreem Logo)

Add Text Node (blue)

Add CDATA (Orange)

Add Processing Node(Yellow)

Add Comment (Purple)

How do I add an attribute to an XML Element?

1. Select an Element in the Tree

2. Press the “+” over the attributes grid.

3. Select the “NewAttribute” in the attribute Grid and edit the name.

As you edit attributes in the grid you can sort the attribute order using the column names. You can also select an attribute in the grid and move it higher or lower using the arrow buttons, .

Can I view the values in the XML Tree?

Yes, The red diamond above the tree will toggle the Tree view. Simply press this button to see the full node values within the tree.

Can I open all nested nodes from the Tree?

Yes, you can.

1. Select the node you want to open in the tree

2. Press the Open All button above the tree.

3. Press the Close All button to do the opposite.

Can I open XML directly from the Internet?

Yes, you can.

1. Press the Globe

2. Enter the URL to the XML File. Press “Download XML”

3. Say yes to the Central Security dialogs.

Good test URLS:

WSDL “Random Bushism” –

Flash RSS –

Central RSS –

What are you waiting for, go edit some XML with XTreeM.

PS: If you find any bugs, submit them within the application,. If you have a feature addition, a small contribution to XTreeM will help make your request a reality .



XTreeM XML Editor Version 0.976

Based on bug reports and feedback from end users, XTreem has made another big leap in functionality and stability.&


1. XML Text Node corruption bug fixed.

2. Tree Toolbar supports context to selected Tree item.

3. Removed initial state error bug.

4. Added button separators in Tree Toolbar.

5. Added descriptive rollover help for all buttons.

6. Rewrote XML rendering class to support of XML caching, printing, formatting.


1. Direct XML editing in TextArea.

2. Add ‘AutoSave’ toggle state to editor. (This is currently on)

3. Add XML Caching for large XML file support.

4. Add text controls.

If you find a bug or have a feature you would like to see in XTreeM please send in a bug report from within XTreeM.

More to come.



Deja-voo – My honeymoon shipped with Flex 1.5

So I am looking through the sample apps in Flex 1.5 and the photoviewer app has some pictures from the resort my wife and I honeymooned in 2001, Los Suenos Marriot in Costa Rica. Deja-voo for me!&

For anyone who has been there, the pool is pretty unmistakable. 3000sq/ft all tiled in small blue tiles with small garden islands throughout. The poolside bar roof is covered with 100+ iguanas. If you throw a French fry, about 5 iguanas will leap off the roof (6ft drop) for a chance at a free meal. We went in August of 2001 and the resort had 250 room, a staff of 100, and 10 rooms were occupied, we had the entire place to ourselves. The resort is done in a Spanish colonial style of mahogany wood beams and large Spanish tile. It is a magical place that is very hard to describe with words, you have to experience it first hand.

If you every get a chance to go to Costa Rica, this resort is simply amazing.



Letters version 0.98 and Letter server source

I fixed some bugs in the client and modifed the gameplay to provide animated motion for shared letters. I also posted the server source code that powers the letter game.&

Server Source

The protocol for letters is very simple. When a letter is moved, the coordinates of the changed letter are sent to the server. The server broadcasts the change to all connected clients and the letter is moved locally. When a user connects, the new client is sent all letter coordinates on the server.

SYNC was designed for rapid development of client / server applications using socket connections. Since the SYNC server is written in Python, you have access to all the resources in the python standard library to shape your server protocol.

If you have a game or product that requires a multi-user server, please contact me at You will be amazed what this little server can do and how well it scales cross-platform on WIN, OSX, LINUX and especially BSD/FreeBSD.