More cryptic notes to myself about execution order in Flash

May 31st, 2007 § 0 comments § permalink

When a nested MovieClip with a custom subclass is created, the order is something like this (I think):

  1. the asset is created (as a “plain” MovieClip: it has its name, dimensions, etc, and can be referred to by name from the containing MovieClip, but it has no methods or properties of its ActionScript class)
  2. its constructor is called
  3. any onLoad() handler is called
  4. frame scripts on the MovieClip’s timeline execute

Nested MovieClip subclass gotcha in ActionScript 2

May 25th, 2007 § 5 comments § permalink

[UPDATE: It looks like Colin Moock's excellent book Essential ActionScript 2.0 talks about this very situation, on page 328. His workaround is to use setInterval to poll the object to see if the custom methods/properties have been set up yet.]

This kind of stuff is always a bit difficult to describe clearly, so I might not even try :P So here are some scratched-in notes for myself:

  • Imagine a MovieClip (mc1) which contains another MovieClip inside it (mc2). This nested instance is created in the authoring tool. It would look like this in the Movie Explorer:
  • Both MovieClips have (different) custom class: let’s call them MovieClass1 and MovieClass2.

The constructor for MovieClass1 looks like this:

class MovieClass1 extends MovieClip {
    function MovieClass1()
        trace("MovieClass1 ctor " + this);

MovieClass2‘s constructor looks shockingly similar:

class MovieClass2 extends MovieClip {
    function MovieClass2()
        trace("MovieClass2 ctor " + this);

Ok. Now we place an instance of MovieClass1 on the stage, name it mc1, and test the movie. Here is the traced output:

MovieClass1 ctor _level0.mc1
MovieClass2 ctor _level0.mc1.mc2

So we know that the constructor for the parent clip is called before the constructor of the child clip.

Note that this is quite unlike C++, for example, where member objects are created before the containing object’s constructor is called (see here for an example), and in fact can cause real issues. For example, suppose MovieClass1‘s constructor wants to call custom methods of MovieClass2. Those calls will fail because mc2 has not yet been initialized! Note that this only applies to methods and properties that exist in the custom class — the MovieClip exists, as a plain old MovieClip, but the custom class hasn’t been associated with it yet.


class MovieClass1 extends MovieClip {
    var mc2:MovieClip; /* placed in Flash authoring tool */
    function MovieClass1()
        trace("MovieClass1 ctor " + this);

class MovieClass2 extends MovieClip {
    function MovieClass2()
        trace("MovieClass2 ctor " + this);
    function customMethod()
        trace("MovieClass2 customMethod()");

The results of running this test:

MovieClass1 ctor _level0.mc1
MovieClass2 ctor _level0.mc1.mc2

Yep. customMethod() is never called!

I hope to continue this in a later post… there are more details about the constructor-calling process that are weird and intriguing!

Flash execution order: introduction

October 4th, 2006 § 3 comments § permalink

This is the first in what I hope to be a series of articles about execution order in Flash. That is, when scripts can be placed on MovieClips, Buttons, timeline frames, event handlers etc, in what order will they execute when the movie is running?

A recent bug in my code inspired these investigations. The results are quite interesting, although I have not come to any hard-and-fast conclusions yet.

But first, a simple experiment:

In a new Flash movie, create a simple MovieClip consisting of two frames. Add some text or some other visual aid, if you like. Then add a script in frame 1 that simply reads: trace("Timeline 1, Frame 1");

In the library pane, make a copy of that MovieClip. Then edit the text inside it (so you can distinguish it from the first), and change the script to read trace("Timeline 2, Frame 1");

Now edit the first MovieClip, and drag an instance of the second into the first. Then place an instance of the first MovieClip on your stage.

I hope that made sense!

flash execution order intro 2

Here’s what it might look like in the Movie Explorer window:


You might also want to set the frame rate of the movie to 1 frame per second, so that it’s easier to watch all the trace()s in the output window.

Now run the movie, and stop it after a few frames have written to the output window. Take a look at the first lines of trace():

Timeline 1, Frame 1
Timeline 2, Frame 1
Timeline 2, Frame 1
Timeline 1, Frame 1
Timeline 2, Frame 1
Timeline 1, Frame 1

Notice anything unexpected?

At the very beginning of the movie, MovieClip 1′s script runs before MovieClip 2. But after that first frame, MovieClip 2′s script executes before MovieClip 1!

I don’t know the reason behind this, but Flash is full of interesting behaviour like this when it comes to execution order. I hope to explore this more in following posts, as well as providing a simple enhancement to trace() that makes it easier to follow order of execution.

I’ve attached the sample FLA file in MX2004 format. Take a look and let me know what you think!

Where Am I?

You are currently browsing the Execution order category at bunnyhero dev.

viagra cialis trial pack
cialis generic 20mg
cialis 10 mg where to buy
viagra sales
generic cialis prices
generic propecia
viagra ireland
generic viagra 50 mg
levitra india
inderal overnight
buy strong viagra
cialis viagra cocktail
does generic viagra work
viagra cheap prices
us cialis online pharmacy
viagra pro online
buy viagra without prescription
sun pharmaceuticals india
uninsured cost of cialis
viagra gold
cheap sildenafil
generic cialas
brand cialis 20
cialis online nz
buy viagra usa
cialis soft tabs canada
tadalafil 20mg
viagra levitra cialis offers
.buy viagra
viagra price in india
viagra for sale australia
discount viagra
buy nolvadex
cialis 5mg
viagra levitra which is best
genaric viagra
ordering viagra onl
cialis no perscription
is levitra sold at walmart
order viagra from canada
viagra patent date
sildenafil citrate
100mg viagra
where to buy viagra in calgary
viagra super active
generic cialis
cialis 36 canada
where to buy genuine viagra online
genaric propecia
viagra video
cialis onlilne
cialis no prescrition
need prescription for viagra in cyprus?
cheep viagra
buy proscar
viagra for sale online
sildenafil online canada
european cialis
buy wholesale viagra
cheapest viagra
no risk pharmacy
levitra 10mg buy
levitra order
viagra canada free sample
ca i buy viagra online
cialis 20 mg
cialis men
cheap cialis generic online
what works as well as viagra
aftermarket viagra
cialis 40 mg
viagra suppliers canada
sildenafil citrate overnight delivery
redtube viagra
generic viagra 50mg
online viagra
where to get viagra online
Sildenafil citrate 50mg
Viagra 50mg pills
very cheap propecia
viagra over the counter walgreens
viagra prices walmart
viagra no prescription online
cialis 20mg price
viagra canada no prescription
viagra canada
viagra on line
cialis for daily use disount
Generic viagra
viagra no prescription
best viagra deals from India
canada customs and cialis
buy levitra online
buy viagra on line
cialis online
generic viagra
where to buy viagra in toronto
viagra professional
i need cialis
buy cialis
cialis online canadian pharmacy
viagra generic
Sildenafil Citrate
cialis fastest shipping
tadalafil dosage
cheap generic viagra pills
viagra prices
supreme suppliers cialis
viagra 4 pack
ed. trusted medstore in cialis
where can i buy finasteride
levitra 100mg uk
propecia generic price
status 365 pills
buy viagra no prescription
cialis doesnt work
cialis overnight
lilly cialis 20mg
buy cialis black
viagra free trial offer
purchase propecia
cialis paypal
Cialis 50mg price
viagra profesionals
black cialis
generic cailis
voucher cialis index
low dose cialis
best viagra online toronto
generic viagra
levitra buy
cialis without prescriptions
viagra quebec
viagra without a prescription
viagra costs walmart
nolvadex buy
tadafil cialis
cheap levitra online india
viagra express
sildenafil citrate
Sildenafil Citrate
cialis for sale canada
finasteride sale
cialis black
canada generic viagra
how to buy viagra from canada
1 mg propecia
is super active cialis a scam
cheapest cialis 20mg
cialis vs viagra
generic levitra overnight delivery
levitra generic
buy real viagra with a echeck
100mg Viagra
cialis 200 mg price
levitra canada
viagra 100 tablets
generic viagra soft tabs
Discount Viagra
ordering cialias
where to buy Propecia
30 day free cialis
ciali sell from usa
viagra online without a prescription
buy dapoxetine online
levitra professional 100mg
overnight pharmacy4u
finasteride 1mg
cheap vigra
viagra for women for sale
Tadalafil canada
Sildenafil Citrate 50mg
generic viagra canada
Viagra online
generic viagra online
buy tadalafil
cialis online canada
cialis 20mg
buy cialis online canada
cialis soft tabs
cheaP viagra
generic cialis 20mg
buy cialis using paypal
reasons to use viagra
pfizer viagra price
Viagra Oklahoma city
buy cialis from india
where to buy viagra
cialis for sale
generic viagra price
30 day free trial of cialis
generic viagra paypal
cialis price
cealis generic
cheap viagra online canada
cialis 10mg
36 hour cialis
viagra no prescription canada pfizer
viagra online 365
viagra cialis combo
cialis no prescription
purchase generic viagra
sildenafil tablets
buy viagra
propecia generic finasteride
generic viagia
ed pro trial pack
generis cialis
buy cialis 20mg
Propecia 1mg
cialis professional
indo viagral
original viagra for sale
buy propecia
Finasteride purchase
cialis daily
shipping viagra to australia
10mg cialis
viagra with dapoxetine overnight
where can I buy cialis 20mg
brand levitra
viagra sale
viagra 100mg
Cialis 5mg Tablets
cialis 20mg prices
cialis pills canada
cialis 10mg vs 20mg
viagra for sale in ireland
buy viagra in canada fast
sildenafil citrate generic
cheap cialis overnight
generic cialis cipla
tadalafil soft gelatin capsules
viagra patent expiration date
generic viargra
buy viagra from germany
cialis black reviews
order viagra
Viagra uk
viagra, no prescription
Order viagra
supreme suppliers viagra
viagra jelly sachet
buying viagra online in montreal
viagra and dapoxetine
viagra no prescription
buy viagra online sydney
buy viagra Australia
cialis without prescription
cheap sildenafil citrate
overnight generic viagra
buy generic cialis
generic viagra blogs
viagra online netherlands
original cialis
cialis paypal payment
dsicount viagra
viagra in united states
cialis 200 mg no prescription
20mg cialis
kamagra for sale
cialis with dapoxetine
canadian levitra vs usa levitra
causes of irectal dysfuction
viagra coupons
viagra usa
buy finasteride
generic viagra from india
tadalafil daily use
ebay + cialis
pfizer viagra without prescription
Finasteride 1mg
viagra pills for sale
cialis overnight shipping
viagra mail order
amazon viagra
cialis promise program
discount cialis 20mg
viagra next day delivery usa
viagra softtabs
viagra coupons and discounts
100 ml viagra for sale
order cialis 20mg
Cheap viagra
ganeric viagra
buy Dapoxetine
bying viagra uk
ggeneric viagra for sale
canadian pharmacies selling viagra
Viagra greate britain
viagra coupon
how can i buy viagra online in canada
price of tadalafil 20 mg
cialis 200mg
buy cialis online in canada
viagra in uk
viagra canada pharmacy
paypal online pharmacy
cialis comparison
viagra nz
pills house
viagra no prescription overnight
Generic Cialis
where can I buy propecia?
10 mg cialis for sale
drugstore 1st
viagra price comparison
viagra no prescrition
canadian generic viagra
buy super viagra
cialis viagra levitra canada
viagra uk
montreal online pharmacy
buy kamagra
viagra for boys
Cheap Viagra
levitra online canadian
finasteride 1 mg
cialis no prescription canada
online pharmacy for cialis
Generic Viagra
canadian cialis online
brand name viagra canada
Buy Viagra online
cialis generic versus brand name
cost of viagra
levitra coupon
viagra no prescription cialis
cipla canada
generic viagra
viagra without a script
tadalafil canada
buy cialis generic
buy cheap cialis
drugstore 365 org order levitra online
viagra india
viagRA online
canada pharmacy generic cialis
best viagra source
buy levitra
cheapest cialis tadalafil 20 mg
tadalafil tablets
sildenafil 100mg
viagra loest prise
cilias 20mg
levitra 20mg
viagra canada online
cheap viagra
Cialis online
order levitra
black tab cialis
cialis usa online
viagra melbourne
buy oral viagra online
buy generic propecia
viagra alcohol effects
planet pharma warehouse pvt ltd
Cheap viagra
Cialis generic alternative
viagra online without prescription
cialis super active review
buy viagra online ireland
200 mg cialis deals online
viagra by mail
buy cialis 20 mg
viagra overnight no prescription
cialis generic 10 mg