Home Tutorials Forums Articles Blogs Movies Library Employment Press
Home » Actionscripts library »  Movieclip Object

Next 5

3D (Camera & Scene)

cubeData = [{colour:0xff9900, // Bottom
        Sides:[
        {x:-50, y:50, z:50}, // UL
        {x:-50, y:50, z:-50}, // OL
        {x:50, y:50, z:-50}, // OR
        {x:50, y:50, z:50} // UR
        ]},
{colour:0xff9900, // Top
        Sides:[
        {x:-50, y:-50, z:-50}, // UL
        {x:-50, y:-50, z:50}, // OL
        {x:50, y:-50, z:50}, // OR
        {x:50, y:-50, z:-50} // UR
        ]},
{colour:0xff8800, // Right
        Sides:[
        {x:50, y:-50, z:50}, // OR
        {x:50, y:50, z:50}, // UR
        {x:50, y:50, z:-50}, // UL
        {x:50, y:-50, z:-50} // OL
        ]},
{colour:0xff8800, // Left
        Sides:[
        {x:-50, y:-50, z:-50}, // OR
        {x:-50, y:50, z:-50}, // UR
        {x:-50, y:50, z:50}, // UL
        {x:-50, y:-50, z:50} // OL
        ]},
{colour:0xffaa00, // Front
        Sides:[
        {x:-50, y:50, z:-50}, // UL
        {x:-50, y:-50, z:-50}, // OL
        {x:50, y:-50, z:-50}, // OR
        {x:50, y:50, z:-50} // UR
        ]},
{colour:0xffaa00, // Back
        Sides:[
        {x:50, y:50, z:50}, // UL
        {x:50, y:-50, z:50}, // OL
        {x:-50, y:-50, z:50}, // OR
        {x:-50, y:50, z:50} // UR
        ]}
];
Objekt3d = function (data3d) {
        this.data3d = data3d;
        this.move3d = function(x, y, z) {
                var k = 0;
                while (k<this.data3d.length) {
                        var i = 0;
                        while (i<this.data3d[k].Sides.length) {
                                this.data3d[k].Sides[i].x = this.data3d[k].Sides[i].x+x;
                                this.data3d[k].Sides[i].y = this.data3d[k].Sides[i].y+y;
                                this.data3d[k].Sides[i].z = this.data3d[k].Sides[i].z+z;
                                i++;
                        }
                        k++;
                }
        };
        this.scale3d = function(x, y, z) {
                var k = 0;
                while (k<this.data3d.length) {
                        var i = 0;
                        while (i<this.data3d[k].Sides.length) {
                                this.data3d[k].Sides[i].x = this.data3d[k].Sides[i].x*x;
                                this.data3d[k].Sides[i].y = this.data3d[k].Sides[i].y*y;
                                this.data3d[k].Sides[i].z = this.data3d[k].Sides[i].z*z;
                                i++;
                        }
                        k++;
                }
        };
        this.rotate3d = function(xa, ya) {
                var rad = Math.PI/180;
                var px;
                var py;
                var pz;
                var sin_xa;
                var sin_ya;
                var cos_xa;
                var cos_ya;
                var tempz;
                var k = 0;
                while (k<this.data3d.length) {
                        var i = 0;
                        while (i<this.data3d[k].Sides.length) {
                                px = this.data3d[k].Sides[i].x;
                                py = this.data3d[k].Sides[i].y;
                                pz = this.data3d[k].Sides[i].z;
                                cos_ya = Math.cos(ya*rad);
                                sin_ya = Math.sin(ya*rad);
                                cos_xa = Math.cos(xa*rad);
                                sin_xa = Math.sin(xa*rad);
                                tempz = (pz*cos_ya)-(px*sin_ya);
                                this.data3d[k].Sides[i].x = (pz*sin_ya)+(px*cos_ya);
                                this.data3d[k].Sides[i].y = (py*cos_xa)-(tempz*sin_xa);
                                this.data3d[k].Sides[i].z = (py*sin_xa)+(tempz*cos_xa);
                                i++;
                        }
                        k++;
                }
        };
};
Kamera3d = function (Objekt3d, distance, angle, loc) {
        this.Objekt3d = Objekt3d;
        this.distance = distance;
        this.angle = angle;
        this.loc = loc;
        this.mc = this.create();
};
Kamera3d.prototype.create = function() {
        return (this.loc.createEmptyMovieClip("camMC"+Stage.camNum, Stage.camNum++));
};
Kamera3d.prototype.render = function() {
        this.mc.clear();
        var z;
        var pers;
        var sx;
        var sy;
        var tx;
        var ty;
        var polygon;
        var k = 0;
        while (k<this.Objekt3d.data3d.length) {
                polygon = [];
                var i = 0;
                while (i<this.Objekt3d.data3d[k].Sides.length) {
                        z = this.Objekt3d.data3d[k].Sides[i].z+this.distance;
                        pers = this.angle/z;
                        sx = this.Objekt3d.data3d[k].Sides[i].x*pers;
                        sy = this.Objekt3d.data3d[k].Sides[i].y*pers;
                        polygon.push({sx:sx, sy:sy});
                        i++;
                }
                z = ((polygon[1].sx-polygon[0].sx)*(polygon[2].sy-polygon[0].sy))-((polygon[1].sy-polygon[0].sy)*(polygon[2].sx-polygon[0].sx));
                if (z>0) {
                        this.mc.beginFill(this.Objekt3d.data3d[k].colour, this.Objekt3d.data3d[k].colour);
                        this.mc.moveTo(polygon[0].sx, polygon[0].sy);
                        this.mc.lineTo(polygon[1].sx, polygon[1].sy);
                        this.mc.lineTo(polygon[2].sx, polygon[2].sy);
                        this.mc.lineTo(polygon[3].sx, polygon[3].sy);
                        this.mc.lineTo(polygon[0].sx, polygon[0].sy);
                }
                k++;
        }
};
Cube3d = new Objekt3d(cubeData);
Szene3D = new Kamera3d(Cube3d, 200, 400, _root);
Szene3D.render();
Szene3D.mc._x = 275;
Szene3D.mc._y = 175;
_root.onEnterFrame = function() {
        Cube3d.rotate3d((this._xmouse+100)/100, (this._ymouse+200)/100);
        Szene3D.render();
};

Posted by: Matthias Kannengiesser | website http://www.flashstar.de
A new property for the Movieclip object
//All Movieclips have properties such as the x position: _x
//This code overwrites some of the Movieclip objects predefined //Methods and replace them with new ones.

//The new property is: anymovieclipname._depth
//This code will only work correctly if you use the duplicateMovieClip,
//attachMovie methods of the Movieclip object:
anymovieclip.duplicateMovieClip("newname",depth)
anymovieclip.attachMovie("linkage","newname",depth)

Posted by: Flashguru | website http://www.flashguru.co.uk
Bounce Function
////////////////////////////////////////////////
//	Bounce Function
//	In German I call it wabber :)
///////////////////////////////////////////////
movieclip.prototype.wabber = function(multiplikator, xskal, yskal, ratio) {
        sX = Number(sX * multiplikator) + Number((xskal - _xscale) * ratio);
        sY = Number(sY * multiplikator) + Number((yskal - _yscale) * ratio);
        _xscale += sX;
        _yscale += sY;
}

//You have to add this on your mc - it's just an example:
onClipEvent (enterFrame) {
        wabber(.9, 150, 150, .3);
}

Posted by: Matthias Kannengiesser | website http://www.flashstar.de
2D pie chart like percentage preloader
/* ... place this 2D pie chart like percentage preloader script by www.advance-media.com
on a movieClip on frame 1, your movie begins on frame 2, Flash MX ...
The piece of pie grows with the percentage loaded.
Add a dynamic text field for the variable "digit" to display the percentage value.
By changing a few lines you get a circular time countdown effect, look (---) */
onClipEvent (load) {
        _root.stop();
        radius = 175;
        step = 1;
        // step is the accuracy of drawing the circular line.
        circle_pi = Math.PI/180;
        b_total = _root.getBytesTotal();
        // --- for the time countdown use the next 2 lines instead of the previous line ---
        //begin = getTimer();
        //duration = 4;	// 4 seconds
}
onClipEvent (enterFrame) {
        degree = 0;
        b_loaded = _root.getBytesLoaded();
        // --- for the time countdown use the next line instead of the previous line ---
        //elapse = getTimer();
        if (ratio>=360) {
                // circle completed, preload done
                _root.play();
        }
        _root.digit = parseInt(b_loaded/b_total*100);
        ratio = b_loaded/b_total*360;
        // --- for the time countdown use the next 2 lines instead of the previous 2 lines ---
        //_root.digit = duration-parseInt((elapse-begin)/1000);
        //ratio = (elapse-begin)/(1000*duration)*360;
        with (this) {
                // drawing the growing piece of pie
                clear();
                lineStyle(0, 0x00FFFF, 0);
                beginFill(0x00FFFF, 100);
                lineTo(0, -radius);
        }
        while (degree-step>=(-ratio)) {
                degree -= step;
                x = -radius*Math.sin(degree*circle_pi);
                y = -radius*Math.cos(degree*circle_pi);
                this.lineTo(x, y);
        }
        // 2004 by www.advance-media.com
        this.endFill();
}

Posted by: Folko Langner | website http://www.advance-media.com
2LineTo on mouse move effect
//currently visible on http://www.lelab.net/tonearea/tone.asp?id=28
//the sound function was Posted by: Michael Tapson on actionscript.org

s1 = new Sound();
s1.attachSound("dotsound1");

var intervalID;
maxlevel = 80;
minlevel = 0;
fadespeed = 10;

function fadeup() {
        clearInterval(intervalID);
        intervalID = setInterval(upOne, fadespeed);
}
function fadedown() {
        clearInterval(intervalID);
        intervalID = setInterval(downOne, fadespeed);
}
function upOne() {
        varSnd = s1.getVolume();
        if (varSndsetVolume(varSnd+1);
        } else {
                clearInterval(intervalID);
        }
        updateAfterEvent();
}

function downOne() {
        varSnd = s1.getVolume();
        if (varSnd>minlevel) {
                s1.setVolume(varSnd-1);
        } else {
                clearInterval(intervalID);
        }
        updateAfterEvent();
}

this.s1.start(0, 100);
this.s1.setVolume(0);

this.fri = .2;
function down() {
        this._xscale += (this.scaX-this._xscale)*fri;
        this._yscale += (this.scaY-this._yscale)*fri;
        if (this._xscale-this.scaX<0.2 and this._xscale-this.scaX>-0.2 and this._yscale-this.scaY<0.2 and this._yscale-this.scaY>-0.2) {
                delete(this.onEnterFrame);
        }
}
this.createEmptyMovieClip("lineF", 1000);
this.createEmptyMovieClip("lineE", 1001);
this.lineE._visible = this.lineF._visible = 0;
this.i = 1;

this.follow = new Object();
this.follow._tl = this;
this.follow.onMouseMove = function() {
        Mouse.show();
        this = this._tl;
        this.alert._alpha -= 2;
        this.alert2._alpha += 1;
        this.distancex = (_xmouse-this.currentX)*this.fri;
        this.distancey = (_ymouse-this.currentY)*this.fri;
        this.currentX += this.distancex;
        this.currentY += this.distancey;
        this.lineE.clear();
        this.lineF.clear();
        this.lineE.lineStyle(0, 0x6790B0, 70);
        this.lineE.lineTo(50, 50);
        this.lineF.lineStyle(0, 0x96C94A, 30);
        this.lineF.lineTo(50, 50);
        if (this.i<50) {
                this.lineE.duplicateMovieClip("lineG"+i, i);
                this.lineF.duplicateMovieClip("lineH"+i+300, i+400);
                this.sq = eval("lineH"+this.i+300);
                this.sq2 = eval("lineG"+this.i);
                this.sq._x = sq2._x= this.currentX;
                this.sq._y = sq2._y= this.currentY;
                this.sq2._rotation += this.currentX/2;
                this.sq._rotation += this.currentX;
                i++;
        } else {
                i = 1;
        }
        updateAfterEvent();
};
this.follow.onMouseDown = function() {
        Mouse.hide();
        _root.fadeup();
        this = this._tl;
        this.alert._alpha = 40;
        this.alert2._alpha = 0;
        for (j=1; j<50; j++) {
                this.sqdown = eval(this["lineG"+j]);
                this.sqdown2 = eval(this["lineH"+j+300]);
                this.sqdown.scaX = this.sqdown.scaY = 300;
                this.sqdown2.scaX = this.sqdown2.scaY = 300;
        }
};
this.follow.onMouseUp = function() {
        Mouse.hide();
        _root.fadedown();
        this = this._tl;
        for (j=1; j<=50; j++) {
                this.sqdown = eval(this["lineG"+j]);
                this.sqdown2 = eval(this["lineH"+j+300]);
                this.sqdown.scaX = this.sqdown.scaY = 0;
                this.sqdown2.scaX = this.sqdown2.scaY = 0;
        }
};
Mouse.addListener(follow);
delete this.lineE;
delete this.lineF;
this.onEnterFrame = function() {
        for (k=1; k<=50; k++) {
                this.sqdown = eval(this["lineG"+k]);
                this.sqdown2 = eval(this["lineH"+k+300]);
                this.sqdown.onEnterFrame = this.sqdown2.onEnterFrame = this.down;
        }
};

Posted by: adrien | website http://www.e-mergency.net

Next 5

Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.