Before proceeding with the presentation of the ActionScript 3 language elements, here is a simple script to see from the beginning how easily you can create objects (text, shapes) into a Flash presentation using ActionScript code.
- Follow these steps:
- Open a new Flash document (ActionScript 3.0).
- Right-click on the first Frame in the Timeline, and then choose Actions.
- In the "Actions panel" (the window used to write ActionScript code) add the following code:
var site:TextField = new TextField(); // declare the "site" variable ("TextField" type)
site.text = "marplo.net"; // add a text in "site" variable
addChild(site); // add the variable (its value) in Flash presentation
- Press "Ctrl+Enter" to see the result
- This ActionScript code will display the text "
marplo.net" in the Flash presentation.
You can create many other elements in a Flash presentation with ActionScript: lines, geometric shapes, animation, etc.
In the next example we add a square to the presentation created above (see also the explanations in comments).
- Continue the above example. In the same Actions panel add the code bellow, after the existing code, as shown in this immage:
- If you have closed the Actions panel, right-click on Frame 1 and choose "Actions".
var square:Shape = new Shape; // declare the "square" variable ("Shape" type)
square.graphics.beginFill(0x08fe08); // add a color to "square", with "beginFill(0xRRGGBB)
// define the "square" (position and size, in pixels), with "graphics" property and "drawRect(X, Y, width, height)" method
square.graphics.drawRect(0, 20, 100,100);
addChild(square); // add the square in Flash presentation
- Press "Ctrl+Enter" to see the rezult. Flash will display a window with a text and a green square like in the picture below.
The FLA file with this example can be downloaded from:
Simple script AS3.
So, step by step, with ActionScript you can create complex Flash presentations, the objects you add and their properties can be controlled with AS3 methods and properties. For example, to add transparency to the square in the example above, you can use the "
beginFill(color, nr_alpha)" method (for "nr_alpha" add a number between 0 and 1), like this:
square.graphics.beginFill(0x08fe08, 0.5);
Daily Test with Code Example
HTML
CSS
JavaScript
PHP-MySQL
Which tag create a highlighted bolded text?
<q> <strong> <em><p>Address: <strong>http://CoursesWeb.net/</strong> - Tutorials.</p>
Which of these CSS codes displays the text bolded?
text-size: 18px; font-style: italic; font-weight: 800;#id {
font-weight: 800;
}
What JavaScript function can be used to call another function multiple times, to a specified time interval?
setInterval() setTimeout() push()function someFunction() { alert("CoursesWeb.net"); }
setInterval("someFunction()", 2000);
Click on the correctly defined variable in PHP.
var vname = 8; $vname = 8; $vname == 8;$vname = 8;
echo $vname;