Some examples of flash/lingo interaction by Thomas Higgins
flash MX lingo getvariable

  Flash 6 in d9
From: Thomas Higgins <thiggins@macromedia.com>
To: "'lingo-l@mail4.fcgnetworks.net'" <lingo-l@mail4.fcgnetworks.net>
Subject: RE: <lingo-l> ANN: Director MX
Date: Tue, 26 Nov 2002 09:49:03 -0800

Robert and others,
There were many questions in Robert's email, I've tried to address each one
of them. Check below my signature and let me know if you have any

Tom Higgins
Product Specialist - Director Team


> Interesting. I take it that this means you could put a stub
> swf with no content in your Director movies as a factory for
> spawning XML parser objects that work properly? This might
> be a good thing...

You could most certainly do that.


> In fact, do you even need an embedded Flash asset to access
> the Actionscript object library, or can you just drop them
> into your code wherever you want them, like script Xtras?

You do not need a sprite on stage as there are global Lingo commands
available in addition to sprite-based methods. But keep in mind that using
the global methods has the same memory impact as a single Flash sprite on
stage would. When you issue the global methods the Flash Asset Xtra
essentially creates an invisible sprite/member combination for you and uses
that instance to contain _all_ globally created objects. Therefore this
single-sprite performance hit is the same if you use the global methods to
create one object or one hundred.

Here is what the code would look like to create objects using the sprite
methods and the global methods, notice how similar they are?

-- create a reference to the Math object
tMath = sprite(1).newObject("Math")

-- do it again but using the global method
tMath = newObject("Math")

The syntax is identical, just remove the sprite reference and it's a global
method. Therefore you can simply sprinkle in objects whenever needed in
your movie without worrying about carrying along some Flash sprite on


> If so, how many other useful objects are there in Flash that
> are currently missing from Director, or not working, that
> this effectively fixes?

There are many objects from ActionScript that can now be created and
referenced in Lingo and I'm not sure about what exact "fixes" you're hoping
to find. The easy way to see the list of objects is this:

- Open Flash MX and the open the Reference window
- Look under Objects
- anything that uses the 'new' creator method can be used in Lingo

On top of those you can also create Camera, Microphone and Math object
references. These don't use the 'new' method as they are implicitly global,
but we special-cased them to be exposed.


> How does the performance compare to native Director objects, and
> are all the features generally compatible with Lingo (i.e., are
> there any datatype conversion issues, etc.)?

To be honest I don't have this kind of performance data handy. As far as
data type conversion issues and other similar troubles, yes there are some.
Flash and Lingo have some data types that are different and you must be
carefull when setting property values to recognize what values to use. For
example I got bit in a case where I kept trying to set a Flash variable to
a Lingo point value (tMyFlashVar = point(x,y)), ActionScript doesn't
understand that data structure so I had to use two integer values instead.
Also there are gotchas that Lingo folks might stumble over, like the fact
that ActionScript zero-indexes arrays (their lists), and as such:

tFlashArray = newObject("Array","entry1","entry2")
put tFlashArray[0]
-- "entry1"
put tFlashArray[1]
-- "entry2"

and when using ActionScript objects you gotta use ActionScript syntax:

put tFlashArray.length
-- 2

So be prepared, if you're going to dabble in two languages be ready to know
about both of those languages.


> On a related topic, one of the biggest questions I want
> answered about the new tighter integration of Flash is
> whether we can now have as many Flash sprites on the stage
> as we want without instantly crippling performance.

Well, I never like phrases like "have as many Flash sprites on the stage as
we want without instantly crippling performance". You may want 15, but the
next guy wants 50. ;) That aside, we did not change the fact that each
Flash sprite gets its own instance of the Flash Xtra and thus the memory
and performance demands of multiple SWF sprites is the same as in previous
releases. We are most definitely looking into changing this so that all
Flash sprites play under one Xtra instance but that's a *significant*
change to the Xtra that we felt was far too much work to accomplish in this
release given everything else that is going on. We have a keen eye on this
moving forward as it would be a big boost for using multiple assets in a
single movie.

(And, from another posting)


Example 1: enhanced getVariable access (version 1)
In previous releases you had getVariable and setVariable, now use an
enhanced getVariable to communicate easier:

// in ActionScript within your SWF
gArray = new Array("hi","Charlie","how","are")

-- then in Lingo use getVariable to get a reference
-- to the array instead of a string representation
pSwfArray = sprite(1).getVariable("gArray",false)

-- now push a new value on to the Array directly
-- from Lingo!

Notice how you're now using the method (and properties!) of the Flash Array
object in Lingo. Bonus. No more calling a frame to trigger a function to
add that value, do it right from Lingo.


Example 2: enhanced getVariable access (version 2)
Say you're using a named movie clip on stage, like a bar charting
component. Now you can pull a reference to that clip into Lingo and go from

-- in my SWF I have the bar chart component on stage
-- and that instance is named gBarChart, then...
pBarChart = sprite(1).getVariable("gBarChart",false)

-- now I can change the labels of the bar chart from
-- within Lingo
pBarChart.setYAxisTitle("some string")

Again, the methods and properties of the object (the bar chart component in
this case) are now exposed to you in Lingo.

Math object, LocalConnection Object, NetStream Object, NetConnection
Object, Array Object... the list goes on.


Beyond the above two examples please also know that you can create these
objects directly from Lingo as well:

pArray = sprite(1).newObject("Array","hi","Charlie","how","are")

or do it without a sprite at all!!!:

pArray = newObject("Array","hi","Charlie","how","are")

The "global methods" (those without a sprite ref) are supported via the
Flash Asset Xtra but you don't have to have a sprite on stage, just the
Xtra in your Xtras folder.

(and from some other mails T.Higgins wrote that day)

> And what about... gXML = new("XML")?

Yup. I chose not to explicitly mention all objects by name, the list is long.

> Also I'm assuming that all the MX actionscript commands etc. will now
> work happily within Director MX?

I'm not sure exactly what you mean by this but I'm inclined to say that it's
not correct. Saying "all the MX actionscript commands...will no work happily
within Director MX" is a dicey statement. We don't support all ActionScript as
an alternate syntax if that's what you meant. We do support access to a wide
variety of Flash objects from Lingo, and once you've pulled an object reference
you can then use its methods/properties as defined in ActionScript, but that's
not the same as "all MX actionscript" in my head. Example:

tMath = newObject("Math")
put gMath.asin(-0.2328)
-- -0.2350

> Oh, that's good - Flash's array functions will be nice to
> have available.

And the Math object too... :)

gMath = newObject("Math")

-- use the math object's floor method
-- 3.0000

-- use the math object's arc cosine method
put gMath.aCos(-1)
-- 3.1416

And so on... Basically any Flash object that supports the 'new' creator method,
or the Math, Camera and Microphone objects (those three are implicitly global
and present, no need to create them) can be created and referenced via Lingo.
For other objects that are created inside a SWF itself you can grab references
using the modified getVariable() command:

gFoo = spriteRef.getVariable("gVarName",false)

The false tells it to get a proper reference instead of a string
representation, thus you can make Lingo references to objects spawned within
your SWF. Sweeeeet.

Home shock + cgi Bits 'n pieces Director Lingo ShockLets Contact