actionscript functions
- Started
- Last post
- 6 Responses
- rizingdamp
hi quick actionscript question...
I have several clips all with the same bit of code attached to them - which seems a waste and a hassle to edit, shouldn't i be able to set a function elsewhere and just re use that? sorry if this is a stupid question. i think the problem i am having is with the targeting...
this is the code i am trying to make a function out of...onClipEvent (load) {
this.speedo = 30;
this.heighto = 375;
this._alpha = 10;
}
onClipEvent (enterFrame) {
if (this._height>=(this.heighto-thi... {
this._height = this.heighto;
} else {
this._height += this.speedo;
}
if (this._alpha != 100) {
this._alpha += 10;
}
}any pointers would be very helpful
cheers
- unfittoprint0
on your main movie _root layer:
//Movieclip prototype [AS1.0]:
MovieClip.prototype.chkMorph = function(){
if (this._height >= (this .heighto-this.speedo )) {
this._height = this.heighto;
} else {
this._height += this.speedo;
}
if (this._alpha != 100) {
this._alpha += 10;
}
}MovieClip.prototype.morph = function(speedo, hieghto, alpha){
clearInterval(morphloop);
this._alpha = alpha;
this.morphloop = setInterval(this,"chkMorph ", 30, speedo, heighto, alpha);
}
}//now you just have to call any movie an use
myMC.morph(30,375,10);
- rizingdamp0
thanks for that.
I tried putting in all that but flash isnt liking it...**Error** Scene=home, layer=Layer 2, frame=1:Line 14: ')' or ',' expected
clearInterval(morphl oop);**Error** Scene=home, layer=Layer 2, frame=1:Line 17: Unexpected '}' encountered
}}looking at what you have done Im kinda understanding it all apart from these bits:
MovieClip.prototype. chkMorphclearInterval(morphl oop);
this.morphloop = setInterval(this,"ch kMorph ", 30, speedo, heighto, alpha)
is it easy to explain or am i a lost cause?
- rizingdamp0
thanks for all this help.
one last question, now the function is set up how do call it?Ive tried attaching this to the movieclip
onClipEvent (load) {
myMC.morph(30, 375, 10);
}but that cant be right.
sorry, being very dumb here
- unfittoprint0
only write actionscrpt in action only layers. copy/paste the actions there. in the last line I gave you an example of how to use it:
name you movieclip instance in your properties panel [ie. myMC].
and the just use the following code:
myMC.morph(30, 375, 10);
note: stop using onClipEvents, it's deprecated code. in fact don't write any code directly to an MC.
- rizingdamp0
hi... still not working, have a look at the fla file
http://www.rizingdamp.com/newros…
thanks for the advice, I havent pissed around much in flash for 2 years, shows how much changed huh
cheers again