Bright Hub
 
Matthew Casperson's Hubfolio

Coppercube Tutorial - ActionScript Scripting

Article by Matthew Casperson (227,413 pts )
Published on Sep 22, 2009

Extend the functionality of a Coppercube application with custom ActionsScript scripting.

In the last two tutorials we have seen how to create a Coppercube application using only the functionality of the Coppercube editor. Thanks to the behaviours that can be assigned to the elements you can create interactive applications without having to write any code. But while these behaviours and elements, like the various cameras, can be combined to create fully functional and interactive applications, some functionality can only be achieved with additional code.

Coppercube applications can be scripted through the SimpleAPI, which is a set of functions that expose the inner properties of the elements in the scene. We will make use of this to create a light that changes colour.

First the Coppercube application needs to be compiled. For this tutorial we will use the same application as the last tutorial, expect for the addition of one light called Light2. It is this light that we will modify via code.

Coppercube supports two scripting languages: ActionScript (Flash or Flex) and Squirrel. ActionScript is used to script the Flash applications, while Squirrel is used to script the Windows applications. This means your target audience (web or Windows) will define what language you use. This will be a web application, so we will use ActionScript.

Scripting Flash Coppercube applications basically involves loading the SWF file created by Coppercube into a new SWF created by your ActionScript compiler. We will use the Flex compiler to create the final scripted application. The SWF you create then modifies the elements inside the Coppercube SWF file.

To keep things simple you can embed the Coppercube SWF inside the final SWF file. The process is described here. We use this same formula for our class called CoppercubeSprite.

CoppercubeSprite.as

First the Coppercube SWF file is embedded. You can use the Embed keyword to add resources into a SWF file, giving you one file to distribute, and also negating the need to load resources from external sources (along with its inherent unreliability). [code]

We set up a function to be called every frame. It is in this function that we can modify the Coppercube scene. [code]

The embedded SWF file is then loaded, with the onCoppercubeLoaded function set to be called when the loading is finished. [code]

Once the embedded SWF file is loaded we set loadingFinished to true to indicate that the Coppercube scene is ready to be modified, and get a reference to the SimpleAPI interface. [code]

Search More About:

Follow Matthew Casperson
Receive weekly updates from Matthew Casperson
 
Bright Hub - Science & Technology Articles, Buyer's Guides, How-To Tips and Software Reviews
About Bright Hub | Contact Us | Advertise with Us | Become a Writer | RSS | Site Map | Terms of Use | Privacy Policy | Copyright Policy
©2010 Bright Hub Inc. All rights reserved. Page copy protected against web site content infringement by Copyscape