Invata cum poti crea desene 2d cu Actionscript



actionscripticon_400-300x300
Exemplul 1: Vom desena doua patrate suprapuse, de culori diferite.
Deschidem un editor si scriem urmatorul cod:
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.Graphics;
public class Rectangles extends Sprite {
public function Rectangles() {
drawColoredRectIn(graphics, 0xFF0000);//prima figura
var rect:Shape = new Shape();
drawColoredRectIn(rect.graphics, 0xFFFF00);//a doua figura
rect.x = 50; //pozitia fata de prima figura
rect.y = 50;
addChild(rect);
}
private function drawColoredRectIn(target:Graphics, color:int):void {
target.lineStyle(1, 0×000000);
target.beginFill(color);
target.drawRect(0, 0, 100, 100); //lungime=latime=100
}
}
}
Salvam cu numele clasei Rectangles.as
Compilam : ./mxmlc Rectangles.as
Vizualizam rezultatul: Opera(sau alt browser)–>Open–>Rectangles.swf
Exmplul 2
Vom desena aceleasi patrate , dar de data asta vom folosi clasa MovieClip(in loc de Shape).
Deschidem un editor si scriem urmatorul cod:
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Graphics;
public class Rectangles2 extends MovieClip {
public function Rectangles2() {
drawColoredRectIn(graphics, 0xFF0000);//prima figura,culoare:rosu
var rect:MovieClip = new MovieClip();
drawColoredRectIn(rect.graphics, 0xFFFF00);//a doua figura,culoare:galben
rect.x = 50;//pozitia fata de prima figura
rect.y = 50;
addChild(rect);patrate
}
private function drawColoredRectIn(target:Graphics, color:int):void {
target.lineStyle(1, 0×000000);
target.beginFill(color);
target.drawRect(0, 0, 100, 100);//lung=latim=100
}
}
}
Salvam cu numele Rectangles2.as
Compilam : ./mxmlc Rectangles2.as
Vizualizam rezultatul: Opera(sau alt browser)–>Open–>Rectangles2.swf


Responses

0 Respones to "Invata cum poti crea desene 2d cu Actionscript"

Trimiteți un comentariu

 
Return to top of page Copyright © 2012 | i-Learn2 Theme Converted into Blogger Template by Dominiq