mercredi 7 décembre 2016

how to migrate form actionscript 2.0 to actionscript 3.0

i am a beginner in flash cs 6. I currently follow a flash tutorial online to create an animation for education. The link to tutorial is http://ift.tt/2gX9aNL

i know how to redifine variabel. i try to migrate script form actionscript 2.0 to actionscript 3.0 but, it is useless. I was hoping that someone can help me convert the code to ActionScript 3.0.

here is the code,

kondisi = 0;
g = 9.8;
timeFaktor = 4;
fungsi waktu
function jamReset() {
    delete waktuSekarang;
    delete waktuTampil;
    waktuSekarang = new Date();
    waktuTampil = new Date();
    pemulaiWaktu = false;
    pauseWaktu = 0;
    txt_Waktu.text = "t = "+0+" s";
}
function jamPause() {
    pauseWaktu = waktuBaru;
    delete waktuSekarang;
    delete waktuTampil;
    waktuSekarang = new Date();
    waktuTampil = new Date();
    pemulaiWaktu = false;
    txt_Waktu.text = "t = "+waktu+" s";
}
function jamBergerak() {
    delete waktuSekarang;
    waktuSekarang = new Date();
    if (!pemulaiWaktu) {
        waktuMulai = waktuSekarang.getTime();
        pemulaiWaktu = true;
    }
    waktuBaru = Number(waktuSekarang.getTime()-waktuMulai)+Number(pauseWaktu);
    detik = waktuBaru/1000;
    waktu = (Math.round(detik*100))/100;
    txt_Waktu.text = "t = "+waktu+" s";
}
fungsi setingan awal sebelum ketapel ditarik
function Setting_awal() {
    Xo = bola._x;
    Yo = bola._y;
    txt_Dx.text = "ΔX = "+(target._x-bola._x)/100+" m";
    txt_Dy.text = "ΔY = "+(bola._y-target._y)/100+" m";
    karet1._x = Xo-10;
    karet1._y = Yo;
    karet2._x = Xo+10;
    karet2._y = Yo;
    _root.karet1.clear();
    _root.karet1.lineStyle(15, 0x003300, 100);
    _root.karet1.moveTo(0, 0);
    _root.karet1.lineTo(-2, 0);
    _root.karet2.clear();
    _root.karet2.lineStyle(15, 0x005500, 100);
    _root.karet2.moveTo(0, 0);
    _root.karet2.lineTo(-15, 0);
    _root.garis1.clear();
    _root.garis2.clear();
    _root.lingkaran.clear();
    mc_var._x = 100000;
}
fungsi setingan setelah bola lepas dari ketapel
function Setting_Bola_Lepas() {
    txt_Dx.text = (target._x-bola._x)/100+" m";
    txt_Dy.text = (bola._y-target._y)/100+" m";
    karet1._x = Xo-10;
    karet1._y = Yo;
    karet2._x = Xo+10;
    karet2._y = Yo;
    _root.karet1.clear();
    _root.karet1.lineStyle(15, 0x003300, 100);
    _root.karet1.moveTo(0, 0);
    _root.karet1.lineTo(-2, 0);
    _root.karet2.clear();
    _root.karet2.lineStyle(15, 0x005500, 100);
    _root.karet2.moveTo(0, 0);
    _root.karet2.lineTo(-15, 0);
    _root.garis1.clear();
    _root.garis2.clear();
    _root.lingkaran.clear();
    mc_var._x = 100000;
}
onEnterFrame = function () {
    kondisi 0, posisi awal semua objek
    if (kondisi == 0) {
        mcberhasil._x = 10000;
        mcgagal._x = 10000;
        bola._x = 100;
        bola._y = 340;
        target._x = 700;
        target._y = 340;
        ketapel1._x = 98;
        ketapel1._y = 349;
        ketapel2._x = 109;
        ketapel2._y = 365;
        jamReset();
        Setting_awal();
    }
    kondisi 1, kondisi saat ketapel 1 di drag                
    if (kondisi == 1) {
        ketapel2._x = ketapel1._x+11;
        ketapel2._y = ketapel1._y+16;
        bola._x = ketapel1._x+2;
        bola._y = ketapel1._y-9;
        Setting_awal();
    }
    kondisi 2, kondisi saat ketapel 2 di drag                
    if (kondisi == 2) {
        ketapel1._x = ketapel2._x-11;
        ketapel1._y = ketapel2._y-16;
        bola._x = ketapel2._x-9;
        bola._y = ketapel2._y-25;
        Setting_awal();
    }
    kondisi 3, kondisi saat bola ditarik                
    if (kondisi == 3) {
        DeltaX = Xo-bola._x;
        DeltaY = Yo-bola._y;
        Rangle = Math.atan2(DeltaY, DeltaX);
        Resultan = Math.sqrt((DeltaX*DeltaX)+(DeltaY*DeltaY));
        Sudut = (Math.round((-Rangle*180/3.14)*10))/10;
        Vo = (Math.round(Resultan*10))/10;
        mc_var.txt_Vo.text = "Vo = "+Vo/10+" m/s";
        mc_var.txt_sudut.text = "Alpha = "+Sudut;
        peletakan mc_var
        mc_var._x = Xo+10+DeltaX;
        mc_var._y = Yo-10+DeltaY;
        pembuat ketapel
        _root.karet1.clear();
        _root.karet1.lineStyle(15, 0x003300, 100);
        _root.karet1.moveTo(0, 0);
        _root.karet1.lineTo(-DeltaX, -DeltaY);
        _root.karet2.clear();
        _root.karet2.lineStyle(15, 0x005500, 100);
        _root.karet2.moveTo(0, 0);
        _root.karet2.lineTo(-DeltaX-15, -DeltaY);
        pembuat tanda panah kemiringan
        _root.createEmptyMovieClip("garis1", 1);
        _root.garis1.lineStyle(3, 0xFF0000, 70);
        _root.garis1.moveTo(Xo, Yo);
        _root.garis1.lineTo(Xo+DeltaX, Yo+DeltaY);
        _root.garis1.lineTo(Xo+DeltaX-(20*Math.cos(Rangle-0.5)), Yo+DeltaY-(20*Math.sin(Rangle-0.5)));
        _root.garis1.lineTo(Xo+DeltaX, Yo+DeltaY);
        _root.garis1.lineTo(Xo+DeltaX-(20*Math.cos(Rangle+0.5)), Yo+DeltaY-(20*Math.sin(Rangle+0.5)));
        pembuat garis horizontal 
        _root.createEmptyMovieClip("garis2", 2);
        _root.garis2.lineStyle(2, 0x000000, 70);
        _root.garis2.moveTo(Xo, Yo);
        _root.garis2.lineTo(Xo+DeltaX, Yo);
        pembuat lingakran
        r = 100;
        x = Xo;
        y = Yo;
        _root.createEmptyMovieClip("lingkaran", 3);
        _root.lingkaran.lineStyle(5, 0x999999, 70);
        _root.lingkaran.moveTo(x+r, y);
        _root.lingkaran.curveTo(r+x, Math.tan(Math.PI/8)*r+y, Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
        _root.lingkaran.curveTo(Math.tan(Math.PI/8)*r+x, r+y, x, r+y);
        _root.lingkaran.curveTo(-Math.tan(Math.PI/8)*r+x, r+y, -Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
        _root.lingkaran.curveTo(-r+x, Math.tan(Math.PI/8)*r+y, -r+x, y);
        _root.lingkaran.curveTo(-r+x, -Math.tan(Math.PI/8)*r+y, -Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
        _root.lingkaran.curveTo(-Math.tan(Math.PI/8)*r+x, -r+y, x, -r+y);
        _root.lingkaran.curveTo(Math.tan(Math.PI/8)*r+x, -r+y, Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
        _root.lingkaran.curveTo(r+x, -Math.tan(Math.PI/8)*r+y, r+x, y);
        agar bergerak melingkar
        if (Resultan>=100) {
            Resultan = 100;
            bola._x = Xo-(100*Math.cos(Rangle));
            bola._y = Yo-(100*Math.sin(Rangle));
        }
        pembuat nol waktu                
        jamReset();
    }
    kondisi4, kondisi bola sesaat setelah dilepas                
    if (kondisi == 4) {
        Setting_Bola_Lepas();
        bola._x = Xo;
        bola._y = Yo;
        kondisi = 5;
    }
    kondisi 5, bola sudah bergerak menempuh lintasan parabola                
    if (kondisi == 5) {
        jamBergerak();
        waktu = (Math.round(detik*100))/100;
        t = waktu*timeFaktor;
        bola._x = Xo+(Vo*(Math.cos(-Rangle))*t);
        bola._y = Yo-(Vo*(Math.sin(-Rangle))*t)+(0.5*g*t*t);
        if (bola._x>target._x or bola._y>500) {
            if (bola.hitTest(target.sensor)) {
                kondisi = 6;
            } else {
                kondisi = 7;
            }
        }
    }
    kondisi 6, jika bola berhasil menumbuk target                
    if (kondisi == 6) {
        jamPause();
        mcberhasil._x = 400;
        mcberhasil._y = 200;
        mcberhasil.tbulang.onPress = function() {
            kondisi = 0;
        };
    }
    kondisi 7, jika bola gagal menumbuk target                
    if (kondisi == 7) {
        jamPause();
        mcgagal._x = 400;
        mcgagal._y = 200;
        mcgagal.tbulang.onPress = function() {
            kondisi = 0;
        };
    }
};
area untuk fungsi drag movie clip
target.onPress = function() {
    kondisi = 1;
    startDrag(target, false, 400, 10, 750, 400);
};
target.onRelease = function() {
    stopDrag();
};
target.onReleaseOutside = function() {
    stopDrag();
};
ketapel1.onPress = function() {
    kondisi = 1;
    startDrag(ketapel1, false, 10, 10, 600, 400);
};
ketapel1.onRelease = function() {
    stopDrag();
};
ketapel1.onReleaseOutside = function() {
    stopDrag();
};
ketapel2.onPress = function() {
    kondisi = 2;
    startDrag(ketapel2, false, 10, 10, 600, 400);
};
ketapel2.onRelease = function() {
    stopDrag();
};
ketapel2.onReleaseOutside = function() {
    stopDrag();
};
bola.onPress = function() {
    kondisi = 3;
    startDrag(bola, false, Xo-100, Yo-100, Xo+100, Yo+100);
};
bola.onRelease = function() {
    stopDrag();
    kondisi = 4;
};
bola.onReleaseOutside = function() {
    stopDrag();
    kondisi = 4;
};

Aucun commentaire:

Enregistrer un commentaire