Director MX - Flash Integration Demos - Using Flash Objects From Scripting
 

 

Using Flash Objects From Scripting
Flash Objects From Scripting is a new feature in Director MX that allows the Director developer to store references to various Flash objects within Lingo itself and then access the properties and methods of that object directly within Director or Shockwave. This allows the Lingo developer the ability to tie in to or enhance the functionality of their Director authored pieces using available Flash elements. One thing that many developers may want to utilize are Flash's component movies. In these demos Dan demonstrates how you can create and store references to Flash objects in Lingo and then access methods and properties of those objects.

There are two ways in which a user can create and/or obtain references to ActionScript objects, either via Flash sprite methods or via new Lingo global methods. In all cases the syntax is the same, it's just a matter of where you want your objects created and whether you actually have a Flash sprite on stage. The global methods can be called with no Flash member or sprite present, but they will require the presence of the Flash Asset Xtra. The demo files show both methods of access on the Array, Date, String and XML objects.

Demo files created by Dan Sadowski.

 

 

Step 1: Create and store references to an ActionScript object
Step 2: Access methods and/or properties of the object

Demo in Action
Downloadable Files

 


Step 1: Create and store references to an ActionScript object

The first step is to create and store a reference to an ActionScript object using Lingo. This can be achieved in two different ways, the first is by using the Flash sprite newObject method, while the second is using the Lingo global newObject method. In order to create objects the demo files use the following code:

-- using the sprite method
myarray = sprite(1).newObject("Array")

-- using the global method
myarray = newObject("Array", 2, 66.5, 12, 4, 5280)

The syntax for the commands is the same and therefore the above two object creations produce slightly different results. The sprite method results in an empty array object while the global method results in a 5 element array containing the values provided. In the case of using the global method it is important to note that you will still require the Flash Asset Xtra as the new Lingo is supported through that Xtra.


Step 2: Access methods and/or properties of the object

Now that we've created and store references to the objects we can now access the various properties and methods of those objects using standard dot-syntax notation. The example files use the following syntax:

-- access an array element
display "Element="&myarray[1] -- set an array element
myArray[1] = 1024
-- convert the array to a string
display "ArrayFromFlash="&myArray.tostring()

I didn't feel compelled to show examples from both movies as the Lingo examples really wouldn't change. In both cases we've stored a reference to an array object in the variable myArray and therefore all properties and methods are available off that variable using myArray.property and myArray.method() sytnax.

 


Demo in Action
-na-


Downloadable Files
Here are links for the source files used to produce this demo, there are four total files. The commented.xml file is used by both the sprite and global method demos and needs to be copied into the same folder as the movies themselves. The FObjects.fla file is a simple Flash movie with a keyframed animation but no ActionScript. Finally there are the two Director movies, GlobalObject.dir and SpriteObject.dir, these each demonstrate object access using the global and the sprite methods respectively.

commented.xml
FObjects.fla
GlobalObject.dir
SpriteObject.dir

 

page last updated 11-Dec-2002 | tom higgins - thiggins@macromedia.com