Mailing List
Home
Forum Home
Flash Pro
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Variable Optimization by the Flash Compiler

Variable Optimization by the Flash Compiler

2004-03-02       - By Jesse Warden

 Back
Reply:     1     2     3     4     5     6  

Well, it started as a designer's tool.  Now, the Flash Ecosystem upon us, I
think AS2 will compile to true classes in 8; my 2 cents.


-- --Original Message-- --
From: Justin Palmer [mailto:justin@(protected)]
Sent: Monday, March 01, 2004 05:45 PM
To: flashnewbie@(protected)
Subject: RE: [Flashnewbie] Variable Optimization by the Flash Compiler


Hi,

Good explanation.  It leads me to think back to my Java experience, and yes
Java does not allow such things like:

<quote>

idx = 11;
function setValue(someVar){
   someVar = 11;
}
setValue("myReallyReallyReallyLongVariableName" + idx);

</quote>

So I guess that is where the compiler does not need to worry about this. So
what you are saying is MM would rather have more flexibility in programming
style than they care about performance.  After all Flash is/used to be a
designers tool and not a programming platform. Hmmmmmmmm.....I think they
have some decisions to make if they really want to push for leading the web
in RIA applications.  Anyways thanks for the answers.

Regards,

Justin Palmer


-- --Original Message-- --
From: Darron J. Schall [mailto:darron@(protected)]
Sent: Monday, March 01, 2004 2:30 PM
To: flashnewbie@(protected)
Subject: Re: [Flashnewbie] Variable Optimization by the Flash Compiler


> I have heard many times to watch your variables lengths in your movies

> to help execute code faster and to make smaller movies.  Is this true?

> If so, why?

Without knowing the complete inner workings of the Flash Player, this answer
is not guaranteed to be correct.  However, this is my best educated guess
being as I have knowledge of compilers, assemblers, and emulators (virtual
machines).

The simple answer is that it takes longer to parse longer pieces of text.
When the variable's value is looked up, the name of the variable is
translated to a location in memory behind the scenes.  The longer the
variable name, the longer it takes to figure out its location in the lookup
table.

The reason Flash doesn't do this automatically is pretty simple too.
Consider the following:

myReallyReallyReallyLongVariableName1 = 1;
myReallyReallyReallyLongVariableName2 = "981247"; // etc

Now, wouldn't it be cool if that was compiled down to m1 and m2,
respectively?  Yup.. except..

What if there's code that dynamically does variable name lookup?

idx = 1;
this["myReallyReallyReallyLongVariableName" + idx] = 11;

Or better yet:

idx = 11;
function setValue(someVar){
   someVar = 11;
}
setValue("myReallyReallyReallyLongVariableName" + idx);


The Flash compiler has no way of knowing that the string inside the brackets
is actually part of the variable name.  Thus, if the variable was renamed at
compile-time, the above two lines of code would break since
this["myReallyReallyReallyLongVariableName" + idx] would be undefined.

This has been a problem with obfuscators that do renaming.. Because of
Flash's dynamic nature, it's very hard to implement.  I want to say it's
impossible.. but, well, some day I hope it happens, and when it does I don't
want to eat my words.

There's also another problem that deals with MovieClip instance names. You
wouldn't want the renamed variable to be the same as a MovieClip instance..
and you'd have to udpate the .swf file to update all of the MovieClip names
if they're used as variable names.  In as2, it's common to do...

class X {
   private var myMovieClipInstanceNameOnTheStage:MovieClip;

}

.. so that you can reference an MC on the Stage inside of your class file.
There's just a whole lot of bookkeeping involved, and if you do it wrong
your movie won't work right.  Then, the question becomes "is it my fault
that the movie doesn't work right, or did the compiler screw it up on it's
own?"

For now, you can always do renaming by hand if you know it's safe.  Make
sure to keep a backup of your original code though..  :-)

-d


-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
Supported by Fig Leaf Software
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
Lower Prices for Certified Training! Check out new lower prices for
Certified Macromedia Training from Fig Leaf Software. Expand your skill set
with courses in ColdFusion, Flash, Rich Internet Applications and .NET in
the new year.  Fig Leaf Software provides
the highest caliber instruction at our training centers in Washington  
D.C., Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your
location.

Get the details at http://training.figleaf.com/
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe, e-mail: flashnewbie-unsubscribe@(protected)
For additional commands, e-mail: flashnewbie-help@(protected)






-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
Supported by Fig Leaf Software
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
Lower Prices for Certified Training! Check out new lower prices for
Certified Macromedia Training from Fig Leaf Software. Expand your skill set
with courses in ColdFusion, Flash, Rich Internet Applications and .NET in
the new year.  Fig Leaf Software provides
the highest caliber instruction at our training centers in Washington  
D.C., Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your
location.

Get the details at http://training.figleaf.com/
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe, e-mail: flashnewbie-unsubscribe@(protected)
For additional commands, e-mail: flashnewbie-help@(protected)


-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
Supported by Fig Leaf Software
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
Lower Prices for Certified Training! Check out new lower prices for
Certified Macromedia Training from Fig Leaf Software. Expand your
skill set with courses in ColdFusion, Flash, Rich Internet
Applications and .NET in the new year.  Fig Leaf Software provides
the highest caliber instruction at our training centers in Washington  
D.C., Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at
your location.

Get the details at http://training.figleaf.com/
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe, e-mail: flashnewbie-unsubscribe@(protected)
For additional commands, e-mail: flashnewbie-help@(protected)