8
// without importing var myBlur:flash.filters.BlurFilter = new flash.filters.BlurFilter(10, 10, 3); The same code, written with an import statement, lets you access the BlurFilter using the class name instead of continually referencing it using the fully qualified name. This can save typing and reduces the chance of making typing mistakes: // with importing import flash.filters.BlurFilter; var myBlur:BlurFilter = new BlurFilter(10, 10, 3); To import several classes within a package (such as the BlurFilter, DropShadowFilter, and GlowFilter) you can use one of two ways to import each class. The first way to import multiple classes is to import each class by using a separate import statement, as seen in the following snippet: import flash.filters.BlurFilter; import flash.filters.DropShadowFilter; import flash.filters.GlowFilter; If you use individual import statements for each class within a package, it becomes time consuming to write and prone to typing mistakes. You can avoid importing individual class files by using a wildcard import, which imports all classes within a certain level of a package. The following ActionScript shows an example of using a wildcard import: import flash.filters.*; // imports each class within flash.filters package The following is a list of the new filter classes: flash.filters.BevelFilter flash.filters.BitmapFilter flash.filters.BlurFilter flash.filters.ColorMatrixFilter flash.filters.ConvolutionFilter flash.filters.DisplacementMapFilter flash.filters.DropShadowFilter flash.filters.GlowFilter flash.filters.GradientBevelFilter flash.filters.GradientGlowFilter // BlurFilter var fBlur:BlurFilter = new BlurFilter(10, 10); // DropShadowFilter var fDropShadow:DropShadowFilter = new DropShadowFilter( 20, angleInDegrees, 0x000000, .8, 16, 16, 1, 3, inner, knockout, hideObject ); // GlowFilter var fGlow:GlowFilter = new GlowFilter( 0x00FF00, 1, 35, 35, 2, 3, inner, knockout ); // ColorMatrixFilter var fColorMatrix:ColorMatrixFilter = new ColorMatrixFilter(aColorMatrix); // setup combobox var aPics:Array = ["arch.jpg", "bellagio.jpg", "boardwalk.jpg", "caesars.jpg", "circus.jpg", "newman.gif", "venetian.jpg"]; var aFilters:Array = [ {label: "Drop Shadow", data: fDropShadow}, {label: "Blur", data: fBlur}, {label: "Glow", data: fGlow}, {label: "Bevel", data: fBevel}, {label: "Gradient Glow", data: fGradientGlow}, {label: "Gradient Bevel", data: fGradientBevel}, {label: "Adjust Color", data: fColorMatrix} ]; var ref:MovieClip = this.createEmptyMovieClip("mcPhoto", 1); var mcl:MovieClipLoader = new MovieClipLoader(); mcl.addListener(this); function loadClip(evt:Object):Void{ mcl.loadClip("images/" + evt.target.value, mcPhoto); } function onLoadInit(target_mc:MovieClip):Void{ target_mc.filters = [ccbFilters.selectedItem.data]; target_mc._x = (Stage.width - target_mc._width) / 2; target_mc._y = (Stage.height - target_mc._height) / 2; target_mc.onPress = function() {this.startDrag();}; target_mc.onRelease = function() {this.stopDrag();}; } function applyFilter(evt:Object):Void{ mcPhoto.filters = [evt.target.selectedItem.data]; tfTitle.filters = [evt.target.selectedItem.data]; } function init():Void{ ccbPics.dataProvider = aPics; ccbPics.addEventListener("change", loadClip); // trigger change event ccbPics.dispatchEvent({type: "change", target: ccbPics}); ccbFilters.dataProvider = aFilters; ccbFilters.addEventListener("change", applyFilter); // trigger change event ccbFilters.dispatchEvent ({type: "change", target: ccbFilters});

Actionscript 2.0 Cheatsheet

  • Upload
    james

  • View
    6.778

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Actionscript 2.0 Cheatsheet

// without importing var myBlur:flash.filters.BlurFilter = new flash.filters.BlurFilter(10, 10, 3); The same code, written with an import statement, lets you access the BlurFilter using the class name instead of continually referencing it using the fully qualified name. This can save typing and reduces the chance of making typing mistakes:

// with importing import flash.filters.BlurFilter; var myBlur:BlurFilter = new BlurFilter(10, 10, 3);

To import several classes within a package (such as the BlurFilter, DropShadowFilter, and GlowFilter) you can use one of two ways to import each class. The first way to import multiple classes is to import each class by using a separate import statement, as seen in the following snippet:

import flash.filters.BlurFilter;import flash.filters.DropShadowFilter;import flash.filters.GlowFilter;

If you use individual import statements for each class within a package, it becomes time consuming to write and prone to typing mistakes. You can avoid importing individual class files by using a wildcard import, which imports all classes within a certain level of a package. The following ActionScript shows an example of using a wildcard import:

import flash.filters.*; // imports each class within flash.filters package

The following is a list of the new filter classes:

flash.filters.BevelFilterflash.filters.BitmapFilterflash.filters.BlurFilterflash.filters.ColorMatrixFilterflash.filters.ConvolutionFilterflash.filters.DisplacementMapFilterflash.filters.DropShadowFilterflash.filters.GlowFilterflash.filters.GradientBevelFilterflash.filters.GradientGlowFilter

// BlurFiltervar fBlur:BlurFilter = new BlurFilter(10, 10);

// DropShadowFiltervar fDropShadow:DropShadowFilter = new DropShadowFilter(

20, angleInDegrees, 0x000000, .8, 16, 16, 1, 3, inner,knockout, hideObject

);

// GlowFiltervar fGlow:GlowFilter = new GlowFilter(

0x00FF00, 1, 35, 35, 2, 3, inner,knockout

);

// ColorMatrixFiltervar fColorMatrix:ColorMatrixFilter = new ColorMatrixFilter(aColorMatrix);

// setup comboboxvar aPics:Array = ["arch.jpg", "bellagio.jpg", "boardwalk.jpg", "caesars.jpg", "circus.jpg", "newman.gif", "venetian.jpg"];var aFilters:Array = [

{label: "Drop Shadow", data: fDropShadow}, {label: "Blur", data: fBlur}, {label: "Glow", data: fGlow},{label: "Bevel", data: fBevel}, {label: "Gradient Glow", data: fGradientGlow},{label: "Gradient Bevel", data: fGradientBevel},{label: "Adjust Color", data: fColorMatrix}

];

var ref:MovieClip = this.createEmptyMovieClip("mcPhoto", 1);var mcl:MovieClipLoader = new MovieClipLoader();mcl.addListener(this);

function loadClip(evt:Object):Void{mcl.loadClip("images/" + evt.target.value, mcPhoto);

}

function onLoadInit(target_mc:MovieClip):Void{target_mc.filters = [ccbFilters.selectedItem.data];target_mc._x = (Stage.width - target_mc._width) / 2;target_mc._y = (Stage.height - target_mc._height) / 2;target_mc.onPress = function(){this.startDrag();};target_mc.onRelease = function(){this.stopDrag();};

}

function applyFilter(evt:Object):Void{mcPhoto.filters = [evt.target.selectedItem.data];tfTitle.filters = [evt.target.selectedItem.data];

}

function init():Void{ccbPics.dataProvider = aPics;ccbPics.addEventListener("change", loadClip);// trigger change eventccbPics.dispatchEvent({type: "change", target:

ccbPics});

ccbFilters.dataProvider = aFilters;ccbFilters.addEventListener("change", applyFilter);// trigger change eventccbFilters.dispatchEvent

({type: "change", target: ccbFilters});}

init();

Page 2: Actionscript 2.0 Cheatsheet

TextFormat Class

var my_format:TextFormat = new TextFormat();my_format.font = "Arial";my_format.size = 80;

this.createTextField("my_text1", this.getNextHighestDepth(), 10, 10, 650, 100);my_text1.text = "Normal.";my_text1.embedFonts = true;my_text1.antiAliasType = "normal";my_text1.setTextFormat(my_format);

this.createTextField("my_text2", this.getNextHighestDepth(), 10, 70, 650, 100);my_text2.text = "Advanced.";my_text2.embedFonts = true;my_text2.antiAliasType = "advanced";my_text2.setTextFormat(my_format);

//BitMapData Class - Create a square rectangle

import flash.display.BitmapData;import flash.filters.BevelFilter;import flash.geom.Point;

var myBitmapData:BitmapData = new BitmapData(100, 80, true, 0xCCCCCCCC);

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

var filter:BevelFilter = new BevelFilter(5, 45, 0xFFFF00, .8, 0x0000FF, .8, 20, 20, 1, 3, "inner", false);

mc.onPress = function() { myBitmapData.applyFilter(myBitmapData, myBitmapData.rectangle, new Point(0, 0), filter);}

Using include// do not enter a ; at the end of the #include

#include "filename.as"

// skinning a button

mx.controls.Button.prototype.falseUpSkin = "MyButtonUpSkin";mx.controls.Button.prototype.falseDownSkin = "MyButtonDownSkin";mx.controls.Button.prototype.falseOverSkin = "MyButtonOverSkin";mx.controls.Button.prototype.falseDisabledSkin ="MyButtonDisabledSkin";

// attachmovie @ initialize positionattachMovie("test_mc", "test_inst", 77, {_x:400, _y:100});

//Context menu

var myContextMenu:ContextMenu = new ContextMenu();myContextMenu.hideBuiltInItems();myContextMenu.builtInItems.print = true;

//Add new custom menu items and calling function fSummaryHandler

var showsum = new ContextMenuItem("Show Summary", ssHandler);var showsum1 = new ContextMenuItem("Show References", ssHandler);var showsum2 = new ContextMenuItem("Send Info", ssHandler);

myContextMenu.customItems.push(showsum);myContextMenu.customItems.push(showsum1);myContextMenu.customItems.push(showsum2);

Page 3: Actionscript 2.0 Cheatsheet

//Adding items to a scroll menu

m2.addItem( "Flashloaded home", "ico00", "", "_blank" );m2.addItem( "Back", "ico01", "$1", "" );

Page 4: Actionscript 2.0 Cheatsheet

//Using the scrollmenubs.addElement("ibs");bs.addElement("idn");bs.addElement("iib");bs.addElement("itn");

// Scroll the iconbarlast.onRelease = function() {

bs.scrollToLast();};first.onRelease = function() {

bs.scrollToFirst();};chgdir.onRelease = function() {

bs.changeDirection();};// Element adding/removingaddE.onRelease = function() {

bs.addElement("emptyClip");

};remC.onRelease = function() {

bs.removeCurrentElement();};

// Element color modifyingmod.onRelease = function() {

red = random(510)-255;green = random(510)-255;blue = random(510)-255;barColorTransform = {rb:red, gb:green, bb:blue,

aa:'100'};barColor = new

Color(bs.getCurrentElement().bar);barColor.setTransform(barColorTransform);

};

// Alertimport mx.controls.Alert;Alert.show("This is a skinned Alert component","Title");

// Customize Alertimport mx.controls.Alert;import mx.styles.CSSStyleDeclaration;

var titleStyles = new CSSStyleDeclaration();titleStyles.setStyle("fontWeight", "bold");titleStyles.setStyle("fontStyle", "italic");

Alert.titleStyleDeclaration = titleStyles;

Alert.show("Name is a required field", "Validation Error")

// using the Alert Object

import mx.controls.Alert;var listenerObj:Object = new Object();listenerObj.click = function(evt) { switch (evt.detail) { case Alert.OK : trace("you hit \"OK\"."); break; case Alert.CANCEL : trace("you hit \"CANCEL\"."); break; }};

Alert.show("ALERT! Do you want to delete the Internet?", "Error", Alert.OK | Alert.CANCEL, this, listenerObj);

Alert.show("Launch Stock Application?", "Stock Price Alert", Alert.OK | Alert.CANCEL, this, myClickHandler, "stockIcon", Alert.OK);

// Using LoadVars

// create an instance of LoadVars to send datavar dataOut:LoadVars = new LoadVars();

function checkUser():Void { dataOut.username = username.text; dataOut.password = password.text; dataOut.send("checkuser1.php", "newwin", "POST");}

enterbtn.addEventListener("click", checkUser);

checkuser1.php<?$users = array( 'Fred' => '0001', 'Jane' => '2000', 'Mary' => '3333');

$d = getdate();$found = false;

foreach($users as $un => $pw) { if ($_POST['username']==$un && $_POST['password']==$pw) { echo 'Welcome. The time here in Washington DC is '.$d['hours'].':'.$d['minutes']; $found = true; break; }}

if (!$found) { echo 'Sorry, you are not cleared to know what time it is now in Washington DC';}?>

// Using XML

// Loading XML

tuteInfo_xml = new XML();tuteInfo_xml.ignoreWhite = true;tuteInfo_xml.onLoad = function(success) { if (success) { trace('Author.xml loaded. Contents are: '+this.toString()); }};tuteInfo_xml.load('author.xml');

// Use a function to loop thru nodes

if (loaded) { xmlNode = this.firstChild; image = []; description = []; total = xmlNode.childNodes.length;

for (i=0; i<total; i++) { image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue; description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;

Or use this function

function processBook(xmlDoc_xml) { // xmlDoc_xml is now a reference to the XML // object where our information is stored for (var n = 0; n<xmlDoc_xml.firstChild.childNodes.length; n++) { trace(xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue);

Page 5: Actionscript 2.0 Cheatsheet

}}

Page 6: Actionscript 2.0 Cheatsheet

// Databinding with Array

//Globalize styles_global.style.setStyle("fontSize", 12); _global.style.setStyle("fontFamily", "_sans");

// More on StylesmyCBX.setStyle("themeColor", "haloOrange"); myDataField.setStyle("themeColor", "haloBlue"); myButton.setStyle("themeColor", "haloGreen"); mybtn2.setStyle("color", "0xFF00FF"); mybtn2.setStyle("themeColor", "0xFF00FF");

// Create ArraymyStatesArray = new Array();myStatesArray.push({data:"AR", label:"Arkansas"});myStatesArray.push({data:"CA", label:"California"});myStatesArray.push({data:"CO", label:"Colorado"});

// For a comboboxmyStates_cbx.dataProvider = myStatesArray;

// For a ListboxmyStates_list.dataProvider = myStatesArray;

// For a DatagridmyStates_grid.dataProvider = myStatesArray;

//Using value pairmyStatesArray = new Array();myStatesArray.push({data:"ME", label:"Maine"});myStatesArray.push({data:"MD", label:"Maryland"});myStatesArray.push({data:"MA", label:"Massachusetts"});myCBX.dataProvider = myStatesArray;myGrid.dataProvider = myStatesArray;

***** MORE ON CLASSES (OOP) ******

// Make a CLASS for everything

class Animals {var commonName:String;var species:String;var currentCount:Number;

Function animalText:String {Return(commonName + " is a member of the " + species +" family, of which there are only "+ currentCount + "left in the world."; }}

// Now instaniate a var lion:Animals = new Animals("Lion", "Mammal", 264000);var goldfish:Animals = new Animals("Gold Fish", "Fish", 1000000000);

// Call the method in the class

trace (lion.animalText());trace (goldfish.animalText());

status_txt.text = e.toString();

} finally { // Delete the 'Employee' object no matter what. if (userName != null) { delete userName; }}

class BroadcastView extends MovieClip{ // declare visual objects var combo:mx.controls.ComboBox; var rec_mc:MovieClip; var oval_mc:MovieClip; var text_mc:MovieClip;

// declare properties of class var colorsArray:Array; var addListener:Function; var value:Number; // constructor public function BroadcastView (){ colorsArray = this.buildArray(); } function onEnterFrame(){ this.postInit(); } function postInit(){ this.fillComboBox(this.colorsArray); this.combo.addEventListener("change",this.changeColor); AsBroadcaster.initialize(this); this.addListener(oval_mc); this.addListener(rec_mc); this.addListener(text_mc); this.onEnterFrame = null; } private function buildArray():Array{ var theArray:Array= new Array(); theArray.push(new TheColor("Red",0xff0000)); theArray.push(new TheColor("Blue",0x0000ff)); theArray.push(new TheColor("Green",0x00ff00)); theArray.push(new TheColor("Yellow",0xffff00)); theArray.push(new TheColor("Pink",0xff00ff)); theArray.push(new TheColor("Cyan",0x00ffff)); return theArray; }

private function fillComboBox(colorsArray){ for(var i:Number=0;i<colorsArray.length;i++){ this.combo.addItem( colorsArray[i].colorName, colorsArray[i].hexColor ); } }

public function changeColor(){ this._parent.broadcastMessage("changeColor",this.value); }}

// Error Handling - How to Handle

var userName = new Employee();try { var returnVal = userName.getEmployeeInfo(); if (returnVal != 0) { throw new Error("Can not find information on employee."); }} catch (e) {