Home
by Julia, blurred

I have just spent an afternoon arriving at the following ActionScript code:

var savedZoomRect = zoomRect;
trace('  - LO savedZoomRect=' + savedZoomRect);
trace('  - LO zoomRect=' + zoomRect);
zoomOutBtn = _root.attachMovie(zoomOutLinkageName,
    'zoomOut_btn_mc', nextButtonDepth++);
trace('  - MM zoomRect=' + zoomRect);
var zoomer = this;			
trace('  - HI zoomRect=' + zoomRect);
trace('  - HI savedZoomRect=' + savedZoomRect);
zoomRect = savedZoomRect;

The middle line (in bold) does not mention my variable zoomRect at all; the method attachMovie is supplied by the system, and does not know about my variable. Nevertheless, this is what the trace commands tell me:

- LO savedZoomRect=(x=0, y=0, w=960, h=640)
- LO zoomRect=(x=0, y=0, w=960, h=640)
- MM zoomRect=(x=0, y=0, w=960, h=640)
- HI zoomRect=
- HI savedZoomRect=(x=0, y=0, w=960, h=640)

In other words, my variable evaporates for no reason at all. Adding the code that copies in to a local variable and back again is necessary to make the code work*. Something here has gone very, very wrong.

* Until the next bit that has inexplicably stopped working since last week.

Updated to add: I have now got the ActionScript to work by replacing all class variables with global variables (so class variable zoomRect is replaced by a global variable _global.zoomer_zoomRect and so on for half a dozen more). This is only needed for Flash 6; I can only assume that one of the changes with Flash 8 was rewriting their script engine to be less lousy.

In Macromedia Flash, 1 + 1 = 11

  • Jan. 6th, 2006 at 3:01 PM
red

What were they thinking? Arrays in ActionScript appear to be associative arrays with syntactic sugar!


var xs= ['hello', 'world', 'foo', 'bar'];
for (var i in xs) {
    trace('control' + (i + 1));
}

Prints something insane like

control31
control21
control11
control01

The upshot of this is that you should not do this. Instead the equivalent in ActionScript of this Python statemenet

for x in xs:
    doSomething(x)

is something like the following:

for (var i = 0; i < xs.length; ++i) {
    var x = xs[i];
    doSomething(x);
}
Madness.

Advertisement

Latest Month

October 2009
S M T W T F S
    123
45678910
11121314151617
18192021222324
25262728293031

Tags

Syndicate

RSS Atom
Powered by LiveJournal.com
Designed by [info]chasethestars