Flash Tutorials - Herong's Tutorial Examples - v3.03, by Dr. Herong Yang
MyMovieClip.as - Adding Graphics and Text
This section provides a tutorial example on how to draw graphics and add texts to the default frame of a movie clip using ActionScript 3 script.
In this section, I want to show you a tutorial example of ActionScript code for creating graphics and text:
// MyMovieClip.as // Copyright (c) 2014, HerongYang.com, All Rights Reserved. // package com.herongyang { import flash.display.*; import flash.text.*; public class MyMovieClip extends MovieClip { private var green:uint = 0x00ff00; private var black:uint = 0x000000; // Building my first frame in the constructor public function MyMovieClip() { addCircle(); addText(); } // Building a shap object private function addCircle():void { graphics.beginFill(green); graphics.lineStyle(5, black); graphics.drawCircle(75, 75, 50); graphics.endFill(); } // Building a text object private function addText():void { var object:TextField = new TextField(); object.text = "Green"; object.x = 50; object.y = 50; addChild(object); } } }
A few things I learned from this example:
Compile MyMovieClip.as and generate the HTML code:
C:\herong>\local\SWFTools\as3compile -X 150 -Y 150 MyMovieClip.as C:\herong>\local\SWFTools\swfdump.exe -E MyMovieClip.swf > MyMovieClip.html
Open MyMovieClip.html in a Web browser. You will see:
Cool. I am able to do some drawing and texting with ActionScript 3 now.
I tried to add more frames and failed. Adobe does not provide any ActionScript 3 API for you to manage the animation timeline or frames.
Table of Contents
Adobe Flash Player Plugin for Firefox
Adobe Flash Player Plugin for Chrome
Adobe Flash Player Plugin for Safari
Adobe Flash Player ActiveX for IE
Using "object" Elements for Flash Files
Using "embed" Elements for Flash Files
"mp3player" - MP3 Music Player
SWFObject - Hidding "object" behind JavaScript
SWFTools - SWF File Manipulation Tools
SWFC Script to Generate Flash SWF Files
ActionScript Embedded in SWFC Script
►AS3Compile - ActionScript 3 Compiler
smiley.as - First ActionScript 3 Example
►MyMovieClip.as - Adding Graphics and Text
ShowSystem.as - Showing System Properties