Chapter 3 Migrasi Dari AS2 ke AS3 · PDF fileMigrasi Dari AS2 ke AS3 Fadhil Hidayat, email:...

Post on 01-Feb-2018

240 views 1 download

Transcript of Chapter 3 Migrasi Dari AS2 ke AS3 · PDF fileMigrasi Dari AS2 ke AS3 Fadhil Hidayat, email:...

Chapter 3

Migrasi Dari AS2 ke AS3

Fadhil Hidayat, email: fadhil_hidayat@yahoo.com, visit: 2persen.wordpress.com

Pelatihan Dasar Action ScriptProgram Ilmu Komputer FPMIPA UPIGIK UPI 16 Oktober 2010

OVERVIEWMigrasi dari AS 2 ke AS 3

Overview

ACTIONSCRIPT 3.0 DAN OOPMigrasi dari AS 2 ke AS 3

Actionscript 3.0 dan OOP

Actionscript 3.0 dan OOP

Class adalah blueprint dariobject. Object dibangunberdasarkan class

Perhatikan pada gambar blueprint atauclass, pada gambar rumah terdapatrancangan pintu, jendela dan cerobongasap. Objek dibangun berdasarkan classnya.

Actionscript 3.0 dan OOP

Ball Class mendefiniskan bentukbola, wana bola, ukuran bola, berat bola, dan lain-lain.

Tiap jenis bola memiliki bentuk, warna, ukuran, dan beratmasing-masing. Khusus untukbola bowling, terdapat lobangpada bola.

Actionscript 3.0 dan OOP

Sebuah mobil telah dikemas sedemikianrupa sehingga penggunanya dapatmenyalakan mobil tersebut tanpa harustahu proses apa yang terjadi didalamnya.

Demikian pula halnya dengan konsepOOP, script dapat dibungkus dalamsuatu class, dan class tersebut dapatdigunakan oleh siapa saja tanpa harusmengetahui proses di dalam class tersebut.

Actionscript 3.0 dan OOP

Perhatikan suatu SPBU, setiap pompamemiliki fitur yang sama yaitu meteranpompa, selang dan gagang pompa. Pompatersebut dapat melayani berbagai bentukmobil menggunakan fitur yang sama. Hal yang demikian dinamakan sebagaipolymorphism.

Polymorphism adalah kemampuan untukmempunyai beberapa bentuk yang berbeda, namun memiliki fitur yang sama.

Actionscript 3.0 dan OOP

Grog roll wheel. Wheel good. Grog doesn’t like rebuilding wheels. They’re heavy, made of stone, and tend to crush feet when they fall over. Grog likes the wheel that his stone-age neighbor built last week. Sneaky Grog. Maybe he’ll carve some holes into the wheel to store rocks, twigs, or a tasty snack. If Grog does this, he’ll have added some-thing new to the existing wheel.

__(demonstrating inheritance long before the existence of computers).

ACTIONSCRIPT 3.0 PROGRAMMING CONCEPTS

Migrasi dari AS 2 ke AS 3

Actionscript 3.0 Programming Concepts

Actionscript 3.0 Programming Concepts

Classes are nothing more than a collection of functions (called methods in this context) that provide a blueprint for any number of instances that are created from it.

__Peter Elst

Actionscript 3.0 Programming Concepts

Actionscript 3.0 adalahscript yang bersifat case-sensitive, untuk ituperhatikan jenis hurufyang digunakan, termasuk besar kecilnyahuruf.

Actionscript 3.0 Programming Concepts

Actionscript 3.0 Programming Concepts

Actionscript 3.0 Programming Concepts

Actionscript 3.0 Programming Concepts

Actionscript 3.0 Programming Concepts

Actionscript 3.0 Programming Concepts

Actionscript 3.0 Programming Concepts

Actionscript 3.0 Programming Concepts

Actionscript 3.0 Programming Concepts

Instacename terdapatpada panel properties. Instancename akanmuncul jika salah satumovieclip dalam kondisiterseleksi.

Movieclip dengan namamc1 pada panel library

Actionscript 3.0 Programming Concepts

CountSheep.as.

package {

import flash.utils.*;

public class CountSheep {

var currentSheep:uint;

var maxSheep:uint;

var countInterval:uint;

function CountSheep(maxSheep:uint) {

this.currentSheep = 0;

this.maxSheep = maxSheep;

}

public function startCounting():void {

countInterval = setInterval(incrementSheep,1000);

}

private function incrementSheep():void {

if(this.currentSheep < this.maxSheep) {

this.currentSheep++;

trace(this.currentSheep+" sheep counted");

} else {

trace("Sleeping ...");

clearInterval(this.countInterval);

}

}

}

}

Method startCounting bersifat public.

Method incrementSheep bersifatprivate.

Actionscript 3.0 Programming Concepts

. Save pada folder yang sama dengan CountSheep.as.Ketiikkan script berikut ini pada panel action frame 1.

var mySleep = new CountSheep(5);

mySleep.startCounting();

Bandingkan apa yang terjadi dengan script berikut ini:

var mySleep = new CountSheep(5);

mySleep.incrementSheep();

Method startCounting bersifatpublic.

Method incrementSheepbersifat private.

Actionscript 3.0 Programming Concepts

variabelStatic.as.

package {

public class variabelStatic {

public static var staticVariable:Object = new Object();

}

}

Buatlah sebuah flash file baru, simpan pada folder yang sama dengan file variabelStatic.as.Ketikkan script berikut ini pada frame 1. Perhatikan apa yang terjadi dengan output program.

trace(variabelStatic.staticVariable.foo);

variabelStatic.staticVariable.foo = “ini variabel static";

trace(variabelStatic.staticVariable.foo );

FLASH OOP GUIDELINESMigrasi dari AS 2 ke AS 3

Flash OOP Guidelines

Hint

Sama halnya dengan Actionscript 2.0,penjelasan tentang class, method besertafungsinya telah terdokumentasi dengan baikpada help file. Dengan mengetahui teknikpembacaan help file Actionscript 3.0, tentuakan mempermudah programmer untuk bekerjadan membuat aplikasi berbasis FlashActionscript 3.0.

Eksplorasi juga script-script tutorial pada web,dan coba gunakan pengetahuan tentang teknikpenulisan class dan function untuk membuatscript tersebut menjadi lebih efisien.

Batas akhir Chapter 1