Accessibility

DevNet Article

Tom Higgins

Tom Higgins

 

Dan Sadowski

Dan Sadowski

www.directordev.com

Using Macromedia Flash Objects From Scripting in Director MX

In Director MX, developers can use a new feature, Flash Objects From Scripting, to create and/or store references to Macromedia Flash objects within Lingo and then access the objects' properties and methods within Director or Shockwave. Thus, a Lingo developer can tie into or enhance the functionality of files they create in Director using Macromedia Flash elements. For instance, many developers may want to use the Macromedia Flash component movies. These demos demonstrate how you can create and store references to Macromedia Flash objects in Lingo and then access the objects' methods and properties.

There are two ways a user can create and/or obtain references to ActionScript objects:

  • Through Macromedia Flash sprite methods
  • Through 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 have a Macromedia Flash sprite on stage. You can call the global methods when no Macromedia Flash member or sprite is present, but this requires that Flash Asset Xtra is present. The demo files show both methods for accessing the Array, Date, String and XML objects.

Requirements

Director MX

Macromedia Flash

Source Files

1. Creating and/or storing references to ActionScript objects using Lingo.

Below, I describe how to create and store references to new ActionScript objects, or, if you already have ActionScript objects in your Macromedia Flash sprite, I explain how to store references to your objects.

a. Create and store references to new ActionScript objects in Lingo.

You can do this in two different ways. The syntax is as follows:

  • Use the Macromedia Flash sprite newObject method, with the following code:

    myarray = sprite(1).newObject("Array")
  • Use the Lingo global newObject method., with the following code:

    myarray = newObject("Array", 2, 66.5, 12, 4, 5280)

Note: The movies already include the complete syntax.

The syntax for the commands is fundamentally the same, however, the code above produces slightly different results. The newObject sprite method creates an empty array object while the global method creates a five-element array, which contains the values you provide. If you use the global method, note that you must require that the Macromedia Flash Asset Xtra is present during playback, since Xtra supports the new Lingo.

b. Store a reference to ActionScript objects that already exist wtihin a Flash sprite.

When using a Macromedia Flash sprite, you can also work with objects that you already created with ActionScript code within the Macromedia Flash file. Simply use the getVariable sprite method. Use the second argument for this method to specify that you want an object reference rather than a string representation of the variable. For examaple, if your Macromedia Flash movie has an internal object called " garray", you can get a Lingo reference to this object with the following code:

myArray = sprite(1).getVariable("garray", false)

Then, you can access properties and methods on the object using Lingo such as:

put myArray.toString()

2. Access methods and/or properties of the object.

Now that you have created and stored references to the objects, you can access the various properties and methods of those objects using standard dot-syntax notation. The example files use the following syntax:

-- to access an array element
put "Element="&myarray[1]

-- to set an array element
myArray[1] = 1024

-- to convert the array to a string
put "ArrayFromFlash="&myArray.tostring()

This tutorial does not show both movies, as the Lingo examples don't change much. Both cases show a reference to an array object in the variable myArray, and therefore all properties and methods are available from that variable using the myArray.property and myArray.method() sytnax.

3. See the demo in action.

Demo screenshot

Figure 1. A screenshot of the demo movie.

4. Open the archive you downloaded to view the sample files.

There are four files, as described below:

  • commented.xml: Both the sprite and global method demos use this file. Copy it into the same folder as the movies.
  • FObjects.fla: A simple Macromedia Flash movie with a keyframed animation that uses ActionScript. It creates some basic
    objects. The SpriteObject.dir movie access these objects using getVariable.
  • GlobalObject.dir: Demonstrates using the global methods, but not the
    sprite methods.
  • SpriteObject.dir: Demonstrates using the sprite methods, but not the global methods.

In this article, you learned how to create and store references to Macromedia Flash objects in Lingo and then access the objects' methods and properties.


About the authors

Tom Higgins has worked at Macromedia for the past four years. He started out as team lead in Tech Support, then joined Director Quality Assurance. He is currently a Director Product Specialist for testing and developer relations. Tom hosts the DirectorDev website.

 

Dan Sadowski has been involved with Macromedia since 1984, when the company was called MacroMind. He works out of his home in Colorado Springs as a software engineer for the Director Development team.

 

Submit feedback on our tutorials, articles, and sample applications.