MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference page 184

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

Example
The following example creates a class called Plant. The Plant constructor takes two
parameters.
// Filename Plant.as
class Plant {
// Define property names and types
var leafType:String;
var bloomSeason:String;
// Following line is constructor
// because it has the same name as the class
function Plant(param_leafType:String, param_bloomSeason:String) {
// Assign passed values to properties when new Plant object is created
this.leafType = param_leafType;
this.bloomSeason = param_bloomSeason;
}
// Create methods to return property values, because best practice
// recommends against directly referencing a property of a class
function getLeafType():String {
return leafType;
}
function getBloomSeason():String {
return bloomSeason;
}
}
In an external script file or in the Actions panel, use the
var pineTree:Plant = new Plant("Evergreen", "N/A");
// Confirm parameters were passed correctly
trace(pineTree.getLeafType());
trace(pineTree.getBloomSeason());
The following example creates a class called ImageLoader. The
takes three parameters.
// Filename ImageLoader.as
class ImageLoader extends MovieClip {
function ImageLoader(image:String, target_mc:MovieClip, init:Object) {
var listenerObject:Object = new Object();
listenerObject.onLoadInit = function(target) {
for (var i in init) {
target[i] = init[i];
}
};
var JPEG_mcl:MovieClipLoader = new MovieClipLoader();
JPEG_mcl.addListener(listenerObject);
JPEG_mcl.loadClip(image, target_mc);
}
}
184
ActionScript language elements
operator to create a Plant object.
new
ImageLoader
constructor

Advertisement

Table of Contents
loading

Table of Contents