Archive for category Flash

asfunction: Definition, Call Paths, and Scope

For anyone unfamiliar with asfunction I will explain the basics first. For those already comfortable with it, but want to understand how to resolve it’s call path and scope to a class instance, feel free to skip to the latter part of this article.
Read the rest of this entry »

5 Comments

Is mx.utils.Delegate.create inefficient?

I use mx.utils.Delegate.create constantly, however in looking at the source code, there are some memory inefficiencies. In the create method, there is a function literal (the var f). By creating this function literal, the create method is actually prolonging the scope of it’s arguments and it’s local variables in the scope of f for the lifetime of f. So what does all this mean? Well, it means that in the scope of f you have create’s argument’s obj and func still available. Yet, f reference’s these values by creating local variables from static properties attached to the function itself, instead of accessing them directly.

Read the rest of this entry »

7 Comments

Magic Strings vs Constants

In looking at pieces of the MM framework, and how a lot of developers write their own code, I’ve noticed a lot of magic string usage. What do I mean by a magic string, let’s examine the following piece of code for a definition:

myComponent.addEventListener("change", this);

In this example, “change” is the magic string. The reason that it is a magic string is that code is dependent on that string being correct, but yet there is no formal assertion that it is correct. For example, if in the example I mispelled “change” as “chnge”, my code would fail silently. Though this may not be catastrophic, you are left to your own debugging methods to figure out what went wrong. Fortunately, there are several ways to remedy this. The easiest and most common is to implement some sort of constant variable in your code to represent the string. For example:

// definition : mx.controls.ListBox.EVT_change = "change";
myComponent.addEventListener(mx.controls.ListBox.EVT_change, this);

In this example, the dispatching object actually has a static property EVT_change that is equal to the string and which is used to represent the string. If you use this method and type in a property that doesn’t exist, you will get an error. So with little effort you can have strict typing, better debugging, and more relaxation time.

4 Comments

IntervalManager

Early on in developing Central apps, I found that I needed something to manage all my Intervals in an application. It was important to have a central place that I could identify, create, and clear intervals, so I developed a singleton manager (IntervalManager) to handle this. In addition, I overloaded the setInterval method, so that one could create delayed calls like setTimeout in javascript, or create an interval that ran N number of times. I managed this by adding a prefixed param N to the setInterval method, which if used tells the interval to run N times, and if not defaults to normal setInterval behavior. Below is the class with usage definitions.
Read the rest of this entry »

13 Comments

File Transfer with Central and Flashcom

I had a theory I wanted to test this morning : Can I transfer files from point 2 point using Central and some sort of proxy. 5 minutes of thought, 5 minutes of code, and the answer was yes. Basically I just read in a binary file, sent the binary data across the wire, wrote the binary on receive, and opened it up. Below is the echo code. NOTE: the flashcom app does nothing but accepts the connection.
Read the rest of this entry »

8 Comments