Thursday, December 18, 2008

Beginner: AS3 XMLList as a Primitive and XML as a Complex Datatypes

Using Flex SDK 3.1.0 build 2710

I'm not sure if this is true across the board after doing a little searching on the web. It seems that people have had different experiences. But as far as I'm concerned right now, XML is being handled as a complex datatype and XMLList is being handled as a primitive datatype.

I'm looking to confirm this though.

Flash has two types of datatypes: primitives and complex. Primitives are datatypes such as Strings or Numbers where each type you associate them a new instance is created.

var abc:String='three wise men';
var copy:String=abc;

abc='two plain dogs';


This above example associates copies the variable abc into the variable copy so that changes in abc later will no be reflected in copy.

Complex datatypes, such as Objects, retain references to an original instance stored in memory.

var dog:Object = {chase:true, likes:'cars'};
var cat:Object = {chase:false, likes:'naps'};




In the above example the variable dog will now reference the same object as the variable cat. Therefore, changing the string 'likes' to mice will change both dog.likes and cat.likes.

XML and XMLList example.

Monday, October 06, 2008

Conway's Game of Life

Here's a neat implementation of Conway's Game of Life using bitmap data filters to run the logic.
"Another way to do the calculations is to use filters which perform all of the calculations that are needed for one step in the Game of Life in a few lines of Actionscript. Filters such as the blur and convolution filters determine the colour of a pixel based on its neighbour’s colours which is exactly the kind of behaviour we need to run the Game of Life calculations. All of the hard work is done behind the scenes, effectively at a lower level which makes the simulation faster.

This makes me want to write my own version of Conway's Game.

Friday, July 25, 2008

Web Performance Optimizations

I appologize for not blogging more, but here's a very helpful posting of web optimization:

A coworker showed this to me. In this he talks about things such as making fewer HTTP requests, using content delivery networks and gzipping files.

Saturday, July 19, 2008

Things You Must Do Before Unloading a SWF File

Wow this is really important. It reads "Danger Will Robinson. Danger!" The following I found from a friend who referenced Colin Moock in which deactivation of a swf requires the following tasks to be disabled.
  • Tell any loaded .swf child assets to disable themselves.
  • Stop any sounds from playing.
  • Stop the main timeline, if it is currently playing.
  • Stop any movie clips that are currently playing.
  • Close any connected network objects, such as instances of Loader, URLLoader, Socket, XMLSocket, LocalConnection, NetConnections, and NetStream.
  • Release all references to cameras and microphones.
  • Unregister all event listeners in the .swf (particularly Event.ENTER_FRAME, and mouse and keyboard listeners)
  • Stop any currently running intervals (via clearInterval()).
  • Stop any Timer objects (via the Timer class’s instance method stop()).
Not doing so apparently allows the swf to consume resources and not get destroyed. Go here to read more:

Monday, June 23, 2008

Beginner: Understanding OOP

Okay. Let talk about programming in general. First of all let's differentiate between two types: procedural and object-oriented.

What is Procedural Programming?
Procedural programming is the type of programming is the common and most intuitive method of programming. The code of a program created using this method is written linearly and is dependent on the order in which each statement of code is written. This is not to say that object-oriented programming is not also procedural at some level, what we need to identify is that the problem is solved using procedural logic. This sort of logic is similar to how people thing.

For example, imagine a clerk at a donut shop:
  1. First, mix ingredients for dough.
  2. Mold it into a ring.
  3. Bake it golden brown.
  4. Coat it with chocolate.
  5. Sprinkle sugar.
Each of these steps must be performed in this exact order and changing any of these steps may change the entire program. If you had asked the clerk to make a bagel instead the clerk might be smart enough to see that most of the steps are the same and say substitute the donut dough for bagel dough and add onions and garlic as toppings. But if you asked the clerk to make a pretzel instead so many steps would have to be rewritten that you might as well not use the same instructions at all.

Modification of the program also requires a person to first understand all of the steps involved before making any changes to the procedure since often the state of different variables may change during the course of the procedure.

What is Object-Oriented Programming?
So then what now is object-oriented programming, or OOP? OOP is a method of breaking down problems into individual blocks of logic. The idea is that the sum of these blocks solves the problem in an elegant yet easy to understand manner.

When we change the logic in the program, of course depending on what is changed, we are also able to be more flexible in our changes. Since the code is divided up into blocks we can change certain blocks without affecting the rest of the code. Also, understanding the big picture of what each of the blocks do allows us to keep track of fewer details in the code and keep the program in general more organized.

Furthermore, the fact that we have separate blocks of logic allows us to create a separation of logic that allows multiple people to work at the same time. As long as each person understands what to expect from each other, they can easily write code that can communicate. Smaller problems being solved at the same time means that, in most cases, we are able to solve the whole problem in shorter time, this may be debated of course by many since there is the overhead of assigning tasks and dividing the problem.

Our same donut shop clerk program might be separated in to groups of tasks.
Dough Tasks:
  1. First, mix ingredients for dough.
  2. Mold it into a ring.
Baking Tasks:
  1. Bake it golden brown.
Topping and Seasonings Tasks:
  1. Coat it with chocolate.
  2. Sprinkle sugar.
Main Donut procedure:
  1. Dough Tasks
  2. Baking Tasks
  3. Topping and Seasonings Tasks
This way we could have two programmers, one to manage the dough tasks and another to manage the seasoning tasks.

Solving Problems Using Design Patterns
Object-oriented programming's main advantage is being able to solve problems through architecture. This is a tremendous advantage because we can solve problems based on different "arrangements" of code. Let's think about this more.

On the contrary, in procedural programming remember a programmer must first understand all of the code before changes are made, rely heavily on conditional logic and reuse code by copy-and-paste.

Most programming problems are common reoccurring issues. The hassle is solving these same problems over and over again when they have very small differences. OOP allows us to make common solutions. These common solutions are called design patterns and are generally architectural solutions. The challenge of OOP does not become memorizing procedures and branches but now gracefully applying design patterns and integrating them into your logic.

Wednesday, April 23, 2008

Lunch-time Experiments

Here's some experiments I had during lunch. I'm thinking about combining these two projects so to create a module that can retell live drawn stories as they fade away. Just a concept right now.

Fades your drawing (click to draw):

Tracks mouse movements; record and playback:

Tuesday, April 15, 2008

Adding Subclipse (SVN) to FlexBuilder 3

I'm running FlexBuilder 3 on my computer at work and to install it I needed the subversion plug-in and a few other plug-ins.

You'll need to add the following :
- Eclipse Java Development Tools
(from Europa Discovery Site)
- Eclipse Plug-in Development Environment
(from Europa Discovery Site)
- Subclipse 1.2.x (Eclipse 3.2+)

If it asks you about the Buckminister plug-in uncheck integrations in subclipse.

Tuesday, February 05, 2008

No exclude.xml in Flash AS3

I've been working for R/GA for some time and things have been crazy. The workload has been fairly heavy with little breathing room so I haven't been posting as much.

Here's some thoughts, by others, on some issues I've run into myself. I'm working on the Nikeplus project and one of the big issues with this project is the size of the project. The project has a much longer life than most of the experiential sites I've been working on and requires maintenance as per our client's requests. This of course creates an immediate issue: things have to be coded fast and slim, which of course means there is much less time to solve problems in elegant ways since old code needs to keep running.

One of the issues you run into is requiring classes to be kept up-to-date. In AS2 classes are overwritten when a parent SWF loads a child SWF. This is because the classes are actually created in the _global space.

Here's an AS3 solution that I've recently found that's pretty interesting using the bridge pattern: