Tài liệu Flash: ActionScript Language Reference- P3 - Pdf 87

case 201
case
Availability
Flash Player 4.
Usage
case expression: statement(s)
Parameters
expression
Any expression.
statement(s)
Any statement or sequence of statements.
Returns
Nothing.
Description
Statement; defines a condition for the
switch
statement. If the
expression
parameter equals the
expression
parameter of the
switch
statement using strict equality (
===
), then Flash Player will
execute statements in the
statement(s)
parameter until it encounters a
break
statement or the
end of the

break;
case 8 :
trace("September");
break;
default :
trace("some other month");
}
CHAPTER 2
ActionScript Language Reference
202 Chapter 2: ActionScript Language Reference
See also
break
,
default
,
=== (strict equality)
,
switch
class 203
class
Availability
Flash Player 6.
Usage
[dynamic] class className [ extends superClass ]
[ implements interfaceName [, interfaceName... ] ]
{
// class definition here
}
Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash
tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in

some directory in the path.
For this reason, it’s good practice to plan your directory structure before you begin creating
classes. Otherwise, if you decide to move class files after you create them, you have to modify the
class declaration statements to reflect their new location.
You cannot nest class definitions; that is, you cannot define additional classes within a
class definition.
CHAPTER 2
ActionScript Language Reference
204 Chapter 2: ActionScript Language Reference
To indicate that objects can add and access dynamic properties at runtime, precede the class
statement with the
dynamic
keyword. To declare that a class implements an interface, use the
implements
keyword. To create subclasses of a class, use the
extends
keyword. (A class can
extend only one class, but can implement several interfaces.) You can use
implements
and
extends
in a single statement. The following examples show typical uses of the
implements
and
extends
keywords:
class C implements Interface_i, Interface_j // OK
class C extends Class_d implements Interface_i, Interface_j // OK
class C extends Class_d, Class_e // not OK
For more information, see in Using ActionScript in Flash.

The following example creates a class called ImageLoader. The
ImageLoader
constructor 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];
}
class 205
};
var JPEG_mcl:MovieClipLoader = new MovieClipLoader();
JPEG_mcl.addListener(listenerObject);
JPEG_mcl.loadClip(image, target_mc);
}
}
In an external script file or in the Actions panel, use the
new
operator to create a ImageLoader
object.
var jakob_mc:MovieClip = this.createEmptyMovieClip("jakob_mc",
this.getNextHighestDepth());
var jakob:ImageLoader = new ImageLoader(" />blueprint/articles/nielsen/spotlight_jnielsen.jpg", jakob_mc, {_x:10, _y:10,
_alpha:70, _rotation:-5});
See also
dynamic
,

function callback() {
trace("interval called: "+getTimer()+" ms.");
}
var intervalID:Number = setInterval(callback, 1000);
You need to clear the interval when you have finished using the function. Create a button called
clearInt_btn
and use the following ActionScript to clear
setInterval()
:
clearInt_btn.onRelease = function(){
clearInterval( intervalID );
trace(“cleared interval”);
};
See also
setInterval()
CHAPTER 2
ActionScript Language Reference
Color class 207
Color class
Availability
Flash Player 5.
Description
The Color class lets you set the RGB color value and color transform of movie clips and retrieve
those values once they have been set.
You must use the constructor
new Color()
to create a Color object before calling its methods.
Method summary for the Color class
Constructor for the Color class
Availability

call.
Color.setRGB()
Sets the hexadecimal representation of the RGB value for a Color object.
Color.setTransform()
Sets the color transform for a Color object.
CHAPTER 2
ActionScript Language Reference
208 Chapter 2: ActionScript Language Reference
Color.getRGB()
Availability
Flash Player 5.
Usage
my_color.getRGB() : Number
Parameters
None.
Returns
A number that represents the RGB numeric value for the color specified.
Description
Method; returns the numeric values set by the last
setRGB()
call.
Example
The following code retrieves the RGB value for the Color object
my_color
, converts the value to
a hexadecimal string, and assigns it to the
myValue
variable. To see this code work, add a movie
clip instance to the Stage, and give it the instance name
my_mc

my_mc
. Then place the following code on Frame 1 in the
main Timeline and select Control > Test Movie:
var my_color:Color = new Color(my_mc);
var myTransform:Object = my_color.getTransform();
myTransform = { ra: 50, ba: 50, aa: 30};
my_color.setTransform(myTransform);
For descriptions of the parameters for a color transform object, see Color.setTransform().
See also
Color.setTransform()
210 Chapter 2: ActionScript Language Reference
Color.setRGB()
Availability
Flash Player 5.
Usage
my_color.setRGB(0xRRGGBB:Number) : Void
Parameters
0xRRGGBB
The hexadecimal or RGB color to be set.
RR
,
GG
, and
BB
each consist of two
hexadecimal digits that specify the offset of each color component. The
0x
tells the ActionScript
compiler that the number is a hexadecimal value.
Description

,
rb
,

ga
,
gb
,
ba
,
bb
,
aa
,
ab
. These properties are explained below.
Returns
Nothing.
Description
Method; sets color transform information for a Color object. The
colorTransformObject

parameter is a generic object that you create from the
new Object
constructor. It has parameters
specifying the percentage and offset values for the red, green, blue, and alpha (transparency)
components of a color, entered in the format 0xRRGGBBAA.
The parameters for a color transform object correspond to the settings in the Advanced Effect
dialog box and are defined as follows:


myColorTransform.gb = 112;
myColorTransform.ba = 12;
myColorTransform.bb = 90;
myColorTransform.aa = 40;
myColorTransform.ab = 70;
You can also use the following syntax to create a
colorTransformObject
parameter:
var myColorTransform:Object = { ra: 50, rb: 244, ga: 40, gb: 112, ba: 12, bb:
90, aa: 40, ab: 70}
212 Chapter 2: ActionScript Language Reference
Example
This example creates a new Color object for a target SWF file, creates a generic object called
myColorTransform
with the properties defined above, and uses the
setTransform()
method to
pass the
colorTransformObject
to a Color object. To use this code in a Flash (FLA) document,
place it on Frame 1 on the main Timeline and place a movie clip on the Stage with the instance
name
my_mc
, as in the following code:
// Create a color object called my_color for the target my_mc
var my_color:Color = new Color(my_mc);
// Create a color transform object called myColorTransform using
// Set the values for myColorTransform
var myColorTransform:Object = { ra: 50, rb: 244, ga: 40, gb: 112, ba: 12, bb:
90, aa: 40, ab: 70};

context menu items, see the ContextMenuItem class entry.
Flash Player has three types of context menus: the standard menu (which appears when you right-
click in Flash Player), the edit menu (which appears when you right-click over a selectable or
editable text field), and an error menu (which appears when a SWF file has failed to load into
Flash Player.) Only the standard and edit menus can be modified with the ContextMenu class.
Custom menu items always appear at the top of the Flash Player context menu, above any visible
built-in menu items; a separator bar distinguishes built-in and custom menu items. You can add
no more than 15 custom items to a context menu. You cannot remove the Settings menu item
from the context menu. The Settings menu item is required in Flash so users can access the
settings that affect privacy and storage on their computers. You also cannot remove the About
menu item from the context menu, which is required so users can find out what version of Flash
Player they are using.
You must use the constructor
new ContextMenu()
to create a ContextMenu object before calling
its methods.
Method summary for the ContextMenu class
Method Description
ContextMenu.copy()
Returns a copy of the specified ContextMenu object.
ContextMenu.hideBuiltInItems()
Hides most built-in items in the Flash Player context menu.
CHAPTER 2
ActionScript Language Reference
214 Chapter 2: ActionScript Language Reference
Property summary for the ContextMenu class
Event handler summary for the ContextMenu class
Constructor for the ContextMenu class
Availability
Flash Player 7.

showItem
. If
false
, the custom menu item is disabled; otherwise, it’s enabled.
Property Description
ContextMenu.builtInItems
An object whose members correspond to built-in context
menu items.
ContextMenu.customItems
An array, undefined by default, that contains
ContextMenuItem objects.
Property Description
ContextMenu.onSelect
Invoked before the menu is displayed.
ContextMenu class 215
var showItem = true; // Change this to false to remove
var my_cm:ContextMenu = new ContextMenu(menuHandler);
my_cm.customItems.push(new ContextMenuItem("Hello", itemHandler));
function menuHandler(obj, menuObj) {
if (showItem == false) {
menuObj.customItems[0].enabled = false;
} else {
menuObj.customItems[0].enabled = true;
}
}
function itemHandler(obj, item) {
//...put code here...
trace("selected!");
}
this.menu = my_cm;

menu items from the specified ContextMenu object. These properties are enumerable and are set
to
true
by default.
Example
In this example, the built-in Quality and Print menu items are disabled for the ContextMenu
object
my_cm
, which is attached to the current Timeline of the SWF file.
var my_cm:ContextMenu = new ContextMenu ();
my_cm.builtInItems.quality=false;
my_cm.builtInItems.print=false;
this.menu = my_cm;
Note: You cannot disable the Settings or About menu items from the context menu.
In the next example, a
for..in
loop enumerates through all names and values of the built-in
menu items of the ContextMenu object,
my_cm
.
var my_cm:ContextMenu = new ContextMenu();
for(eachProp in my_cm.builtInItems) {
var propName = eachProp;
var propValue = my_cm.builtInItems[propName];
trace(propName + ": " + propValue);
}
ContextMenu.copy() 217
ContextMenu.copy()
Availability
Flash Player 7.

this.menu = my_cm;
for (var i in clone_cm.customItems) {
trace("clone_cm-> "+clone_cm.customItems[i].caption);
}
for (var i in my_cm.customItems) {
trace("my_cm-> "+my_cm.customItems[i].caption);
}
218 Chapter 2: ActionScript Language Reference
ContextMenu.customItems
Availability
Flash Player 7.
Usage
my_cm.customItems:Array
Description
Property; an array of ContextMenuItem objects. Each object in the array represents a context
menu item that you have defined. Use this property to add, remove, or modify these custom
menu items.
To add new menu items, you first create a new ContextMenuItem object, and then add it to the
menu_mc.customItems
array (for example, using Array.push()). For more information about
creating new menu items, see the ContextMenuItem class entry.
Example
The following example creates a new custom menu item called
menuItem_cm
with a caption of
“Send e-mail” and a callback handler named
emailHandler
. The new menu item is then added
to the ContextMenu object,
my_cm

This method hides only menu items that appear in the standard context menu; it does not affect
items that appear in the edit or error menus. For more information about the different menu
types, see the ContextMenu class entry.
This method works by setting all the Boolean members of
my_cm.builtInItems
to
false
. You
can selectively make a built-in item visible by setting its corresponding member in
my_cm.builtInItems
to
true
(as demonstrated in the following example).
Example
The following example creates a new ContextMenu object named
my_cm
whose built-in menu
items are hidden, except for Print. The menu object is attached to the current Timeline.
var my_cm:ContextMenu = new ContextMenu();
my_cm.hideBuiltInItems();
my_cm.builtInItems.print = true;
this.menu = my_cm;
220 Chapter 2: ActionScript Language Reference
ContextMenu.onSelect
Availability
Flash Player 7.
Usage
my_cm.onSelect = function (item:Object, item_menu:ContextMenu) : Void{
// your code here
}

}
if(obj instanceof Button) {
trace("Button: " + obj);
}
}
my_cm.onSelect = menuHandler;
my_mc.menu = my_cm;
my_btn.menu = my_cm;
ContextMenuItem class 221
ContextMenuItem class
Availability
Flash Player 7.
Description
You use the ContextMenuItem class to create custom menu items to display in the Flash Player
context menu. Each ContextMenuItem object has a caption (text) that is displayed in the context
menu, and a callback handler (a function) that is invoked when the menu item is selected. To add
a new context menu item to a context menu, you add it to the
customItems
array of a
ContextMenu object.
You can enable or disable specific menu items, make items visible or invisible, or change the
caption or callback handler associated with a menu item.
Custom menu items appear at the top of the context menu, above any built-in items. A separator
bar always divides custom menu items from built-in items. You can add no more than 15 custom
items to a context menu. Each item must contain at least one visible character— control
characters, newlines, and other white space characters are ignored. No item can be more than 100
characters long. Items that are identical to any built-in menu item, or to another custom item, are
ignored, whether the matching item is visible or not. Menu items are compared without regard to
case, punctuation, or white space.
None of the following words can appear in a custom item: Macromedia, Flash Player, or Settings.

[ visible:Boolean] ] ] ) : ContextMenuItem
Parameters
caption
A string that specifies the text associated with the menu item.
callbackFunction
A function that you define, which is called when the menu item is selected.
separatorBefore
A Boolean value that indicates whether a separator bar should appear above
the menu item in the context menu. The default value is
false
. This parameter is optional.
enabled
A Boolean value that indicates whether the menu item is enabled or disabled in the
context menu. The default value is
true
. This parameter is optional.
visible
A Boolean value that indicates whether the menu item is visible or invisible. The
default value is
true
. This parameter is optional.
Returns
A reference to a ContextMenuItem object.
Description
Constructor; creates a new ContextMenuItem object that can be added to the
ContextMenu.customItems
array.
Example
This example adds Start and Stop menu items, separated by a bar, to the ContextMenu object
my_cm

function onPause(obj, menuItem) {
trace("You chose: " + menuItem.caption);
}
this.menu = my_cm;
224 Chapter 2: ActionScript Language Reference
ContextMenuItem.copy()
Availability
Flash Player 7.
Usage
menuItem_cmi.copy() : ContextMenuItem
Returns
A ContextMenuItem object.
Description
Method; creates and returns a copy of the specified ContextMenuItem object. The copy includes
all properties of the original object.
Example
This example creates a new ContextMenuItem object named
original_cmi
with the caption
Pause and a callback handler set to the function
onPause
. The example then creates a copy of the
ContextMenuItem object and assigns it to the variable
copy_cmi
.
var original_cmi:ContextMenuItem = new ContextMenuItem("Pause", onPause);
function onPause(obj:Object, menu:ContextMenu) {
trace("pause me");
}
var copy_cmi:ContextMenuItem = original_cmi.copy();

function stopHandler(obj, item) {
trace("Stopping... "+getTimer()+"ms");
startMenuItem.enabled = true;
stopMenuItem.enabled = false;
}
function startHandler(obj, item) {
trace("Starting... "+getTimer()+"ms");
startMenuItem.enabled = false;
stopMenuItem.enabled = true;
}
this.menu = my_cm;


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status