AS3 variables handling by AVM/compiler/scope

Posted by jchmielewski on Stack Overflow See other posts from Stack Overflow or by jchmielewski
Published on 2010-04-12T14:45:23Z Indexed on 2010/04/12 18:33 UTC
Read the original article Hit count: 303

Filed under:
|
|

I have couple of questions about AS3 variables handling by AVM/compiler/scope

.1. This code in Flash will throw an error:

function myFunction() {
    var mc:MovieClip=new MovieClip();
    var mc:MovieClip=new MovieClip();
}

but it won`t throw an error in Flex (only warning in Editor). Why?


.2. How Flash sees variables in loops? Apparently this:

for (var i:int=0; i<2; i++) {
    var mc:MovieClip=new MovieClip();
}
isn`t equal to just:
var mc:MovieClip=new MovieClip();
var mc:MovieClip=new MovieClip();
because it will throw an error again as earlier in Flash, but in Flex in function not? Is Flash changing somehow my loop before compilation?


.3. Where in a class in equivalent to timeline in Flash - where in class I would put code which I put normally on timeline (I assume it is not constructor because of what I have written earlier, or maybe it`s a matter of Flash/Flex compiler)?

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about flash