tilføj objekt i actionscript
Hejsa,Jeg har fundet en tutorial på nettet: http://www.lionbichstudios.com/flash_tutorials_actionscript_waterbubbles.html og selve actionscriptet ser således ud:
// set global constants
centerx = 390;
// screen center x
centery = 90;
// screen center y
pval = 390;
// strength of perspective
c = 0;
// counter to keep track of depths, etc
// create empty movieclip to control stuff
this.createEmptyMovieClip("mc", 1);
// make one instance to start with.
newInst();
// onEnterFrame code for controller that randomly creates bubbles
mc.onEnterFrame = function() {
// chance of 1 in 100 that new instance is created.
if (Math.floor(100*Math.random()) == 0) {
newInst();
}
// increase counter
c++;
};
// function to create new instance and attach event scripts
function newInst() {
this.attachMovie("bubble", "b"+c, c+10);
this["b"+c].onLoad = function() {
// hide the bubble for now
this._visible = false;
// set initial values
this.bx = 300*Math.random()-150;
// base x coord for sine
this.y = 75;
// initial y coord
this.bz = 300*Math.random()-150;
// base z coord for sine
this.cnt = 5000*(2*Math.PI)*Math.random();
// randomize counter for sine
this.wl = 8;
// wavelength for sine calculations
this.amp = 120;
// amplitude for sine wave
this.ysp = -1;
// speed y direction (minus for upward motion)
};
// start the onLoad script manually
this["b"+c].onLoad();
// the onEnterFrame code moves the bubble
this["b"+c].onEnterFrame = function() {
// change the x,y,z coords
this.x = this.bx+(this.amp*Math.sin(this.cnt/this.wl));
this.y += this.ysp;
this.z = this.bz+((this.amp/2)*Math.sin(this.cnt/this.wl));
// increase counter on which sin and cosine are based
this.cnt += 0.05;
// call the function that applies 3d effects to this bubble
m3d(this, this.x, this.y, this.z);
// check whether this instance is off screen, if so delete it
if (this._y<-150) {
this.removeMovieClip();
}
// now that it's in place, let show the bubble
this._visible = true;
};
}
// this function does the 3d stuff
function m3d(obj, x, y, z) {
// calculate perspective value
ps = _root.pval/(_root.pval+z);
// change the object's properties
with (obj) {
// set 2d coords
_x = centerx+(obj.x*ps);
_y = centery+(obj.y*ps);
// set scale and alpha
_xscale = 100-(z/2);
_yscale = 100-(z/2);
_alpha = 100-(z/2);
}
}
Men jeg vil gerne tilføje nogle flere objekter, altså, så jeg har flere forskellige bobler som svæver op - men hvordan gør jeg det?
På forhånd tak for hjælpen!
