0% found this document useful (0 votes)
232 views6 pages

ActionScript & HTML5 Coding Guide

The document provides code snippets for common actions in ActionScript and HTML5, such as stopping/starting playback, navigating between frames, responding to mouse/click events, loading/positioning objects, and fading/animating objects. It compares the syntax for these actions in ActionScript versus HTML5.

Uploaded by

lighthouse12345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
232 views6 pages

ActionScript & HTML5 Coding Guide

The document provides code snippets for common actions in ActionScript and HTML5, such as stopping/starting playback, navigating between frames, responding to mouse/click events, loading/positioning objects, and fading/animating objects. It compares the syntax for these actions in ActionScript versus HTML5.

Uploaded by

lighthouse12345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Action

ActionScript

HTML5

Stop at this frame

stop();

this.stop();

Click to go to frame and stop gotoAndStop(5);

this.gotoAndStop(5);

Click to go to frame and play gotoAndPlay(5);

this.gotoAndPlay(5);

Click to go to a web page

navigateToURL(new
URLRequest("http://www.adobe.com"), "_blank");

window.open("http://www.adobe.com", "_blank");

Custom mouse cursor

function fl_CustomMouseCursor(event:Event)

function fl_CustomMouseCursor() {

this.btnNavigate.x = stage.mouseX;
instance_name_here.x = stage.mouseX;

this.btnNavigate.y =
stage.mouseY;
this.instance_name_here.y =
instance_name_here.y = stage.mouseY; stage.mouseY;
}
Mouse.hide();
Play a movie clip

instance_name_here.play();

this.instance_name_here.play();

Stop a movie clip

instance_name_here.stop();

this.instance_name_here.stop();

Click to hide an object

instance_name_here.addEventListener(MouseEv this.instance_name_here.addEventListener("click",
ent.CLICK, fl_ClickToHide);
fl_ClickToHide.bind(this));
function fl_ClickToHide(event:MouseEvent):void
{

function fl_ClickToHide()
instance_name_here.visible = false;

this.instance_name_here.visible = false;
}

Show an object

instance_name_here.visible = true;

this.instance_name_here.visible = true;

Click to position an object

instance_name_here.addEventListener(MouseEv this.instance_name_here.addEventListener("click",
ent.CLICK, fl_ClickToPosition);
fl_ClickToPosition.bind(this));

function
fl_ClickToPosition(event:MouseEvent):void

function fl_ClickToPosition()
{

{
this.instance_name_here.x = 200;
instance_name_here.x = 200;
this.instance_name_here.y = 100;
instance_name_here.y = 100;
}
}
Click to display a text field

instance_name_here.addEventListener(MouseEv this.instance_name_here.addEventListener("click",
ent.CLICK, fl_ClickToPosition);
fl_ClickToPosition.bind(this));
var fl_TF:TextField;

var fl_TF = new createjs.Text();

var fl_TextToDisplay:String = "Lorem ipsum dolor


sit amet.";

var fl_TextToDisplay = "Lorem ipsum dolor sit


amet.";

function
fl_ClickToPosition(event:MouseEvent):void

function fl_ClickToPosition()
{

{
fl_TF.x = 200;
fl_TF = new TextField();
fl_TF.y = 100;
fl_TF.autoSize =
TextFieldAutoSize.LEFT;

fl_TF.color = "#ff7700";

fl_TF.background = true;

fl_TF.font = "20px Arial";

fl_TF.border = true;

fl_TF.text = fl_TextToDisplay;

fl_TF.x = 200;

this.addChild(fl_TF);

fl_TF.y = 100;

fl_TF.text = fl_TextToDisplay;
addChild(fl_TF);
}
Mouse click event

instance_name_here.addEventListener(MouseEv this.instance_name_here.addEventListener("click",
ent.CLICK, fl_MouseClickHandler);
fl_MouseClickHandler.bind(this));
function
fl_MouseClickHandler(event:MouseEvent):void

Mouse over event

function fl_MouseClickHandler()

instance_name_here.addEventListener(MouseEv var frequency = 3;


ent.MOUSE_OVER, fl_MouseOverHandler);
stage.enableMouseOver(frequency);
function
fl_MouseOverHandler(event:MouseEvent):void
this.instance_name_here.addEventListener("mouse
over", fl_MouseOverHandler);
function fl_MouseOverHandler()

Mouse out event

instance_name_here.addEventListener(MouseEv var frequency = 3;


ent.MOUSE_OUT, fl_MouseOutHandler);
stage.enableMouseOver(frequency);
function
fl_MouseOutHandler(event:MouseEvent):void
this.instance_name_here.addEventListener("mouse
out", fl_MouseOutHandler);
function fl_MouseOutHandler()

Move horizontally

instance_name_here.x += 100;

this.instance_name_here.x+=100;

Move vertically

instance_name_here.y += 100;

this.instance_name_here.y+=100;

Rotate once

instance_name_here.rotation += 45;

this.instance_name_here.rotation+=45;

Rotate continuously

instance_name_here.addEventListener(Event.EN this.addEventListener("tick",fl_RotateContinuously.b
TER_FRAME, fl_RotateContinuously);
ind(this));
function fl_RotateContinuously(event:Event)

function fl_RotateContinuously(){

this.instance_name_here.rotation+=10;
instance_name_here.rotation += 10;

}
Animate horizontally

instance_name_here.addEventListener(Event.EN this.addEventListener("tick",
TER_FRAME, fl_AnimateHorizontally);
fl_AnimateHorizontally.bind(this));
function fl_AnimateHorizontally(event:Event)

function fl_AnimateHorizontally()

{
instance_name_here.x += 10;

}
Animate vertically

this.instance_name_here.x+=10;
}

instance_name_here.addEventListener(Event.EN this.addEventListener("tick",
TER_FRAME, fl_AnimateVertically);
fl_AnimateVertically.bind(this));
function fl_AnimateVertically(event:Event)

function fl_AnimateVertically()

{
instance_name_here.y += 10;

}
Fade in a movie clip

this.instance_name_here.y+=10;
}

instance_name_here.addEventListener(Event.EN this.addEventListener('tick',
TER_FRAME, fl_FadeSymbolIn);
fl_FadeSymbolIn.bind(this));
instance_name_here.alpha = 0;

this.instance_name_here.alpha = 0;

function fl_FadeSymbolIn(event:Event)

function fl_FadeSymbolIn()

{
instance_name_here.alpha += 0.01;

this.instance_name_here.alpha += 0.01;

if(instance_name_here.alpha >= 1)

if(this.instance_name_here.alpha >= 1)

instance_name_here.removeE
this.removeEventListener('tick',
ventListener(Event.ENTER_FRAME,
fl_FadeSymbolIn.bind(this));
fl_FadeSymbolIn);

}
}
Fade out a movie clip

}
}

instance_name_here.addEventListener(Event.EN this.addEventListener('tick',
TER_FRAME, fl_FadeSymbolOut);
fl_FadeSymbolOut.bind(this));
instance_name_here.alpha = 1;

this.instance_name_here.alpha = 1;

function fl_FadeSymbolOut(event:Event)

function fl_FadeSymbolOut()

{
instance_name_here.alpha -= 0.01;

this.instance_name_here.alpha -= 0.01;

if(instance_name_here.alpha <= 0)

if(this.instance_name_here.alpha <= 1)

instance_name_here.removeE
this.removeEventListener('tick',
ventListener(Event.ENTER_FRAME,
fl_FadeSymbolOut.bind(this));
fl_FadeSymbolOut);
}
}
}
}
Click to load image from
library

instance_name_here.addEventListener(MouseEv this.instance_name_here.addEventListener('click',fl_
ent.CLICK, fl_ClickToLoadImageFromLibrary);
ClickToLoadImageFromLibrary.bind(this));
function
function fl_ClickToLoadImageFromLibrary()
fl_ClickToLoadImageFromLibrary(event:MouseEv
ent):void
{
{
// If you want to add a different image
from the library,

var libImage = new lib.MyImage();


this.addChild(libImage);

// enter a different name in the Class


text field at step 4 above and in the code below.

var libImage:MyImage = new


MyImage();
var holder:Bitmap = new
Bitmap(libImage);
addChild(holder);
}
Add instance from library

var fl_MyInstance:LibrarySymbol = new


LibrarySymbol();

var fl_MyInstance = new lib.LibrarySymbol();


this.addChild(fl_MyInstance);

addChild(fl_MyInstance);

You might also like