|
-
KoolMoves Moderator
Action script question Prototype and movieLoader
What am I doing wrong here. This is pulled from a test for a larger project, here I have a movieclip mc1 with child movieclip called canvas to load an image into. So far so good. Now using the movieLoader I want when loadComplete to scale the clip mc1 down sort of a thumbnail representation of the image. Plan to add loading prograss bar next but When I call a prototype function from a movie that has been loaded this way it doesn't seem to work.
code:
movieClip.prototype.scale=function(amt){
this._xscale=amt;
this._yscale=amt;
}
movieClip.prototype.fadeDown=function(){
this.onEnterFrame=function(){
while (this._alpha>0){
this._alpha-=1;
}//end while
}//end enter frame
}//end
mcLoader = new MovieClipLoader();
listener = new Object();
listener.onLoadComplete=function(target){
target.scale(50)
target._parent._rotation=5
target._parent.fadeDown()
}
mc2.fadeDown;
mcLoader.addListener(listener);
mcLoader.loadClip("galleries/gallery1/balloons.jpg", mc1.canvas);
Last edited by blanius; 08-18-2006 at 09:14 PM.
Reason: forgot to include code
-
Bret, these are causing the problems.
- The class should be MovieClip with a capital M .
- mc2.fadeDown should be mc2.fadeDown()
- the while construction should be an if construction otherwise the alpha value will already become 0 on the first enterFrame event.
A little suggestion.
When using an event function like onEnterFrame iside a prototype function it might be wise to store the original function and call it from within the new function otherwise the function will be replaced if it already exists. It's also best to clear the onEnterFrame function when the fade is completed so it doesn't take up cpu power anymore.
-
KoolMoves Moderator
Thanks man, Tired eyes from too many hours at the keys
-
KoolMoves Moderator
 Originally Posted by w.brants
When using an event function like onEnterFrame iside a prototype function it might be wise to store the original function and call it from within the new function otherwise the function will be replaced if it already exists. It's also best to clear the onEnterFrame function when the fade is completed so it doesn't take up cpu power anymore.
Could you show me an example of how I store the original function and clearing the function.
-
You can clear an onEnterFrame function by setting it to null .
Storing is something like this
Code:
MovieClip.prototype.fadeDown=function(){
if (!this.oldEnterFrame) this.oldEnterFrame = this.onEnterFrame;
this.onEnterFrame = function(){
this.oldEnterFrame();
if (this._alpha > 0){
this._alpha -= 1;
} else {
this.onEnterFrame = this.oldEnterFrame;
this.oldEnterFrame = null;
}
}
}
You copy the existing onEnterFrame function into oldEnterFrame (you may name it differently). You call that each onEnterFrame and your own routine. When the fade is finished, you copy back the old function. That way if the mc already had an onEnterFrame fuction it still will work. If there was no function, it will set back that state when the fade is finished so the onEnterFrame function is cleared.
-
KoolMoves Moderator
I had wondered about the practice of setting onEnterFrame like this. Maybe it would be better to use a setInterval funtcion instead.
I have several prototype things I'd like to use often like EaseTo fadeDown fadeUp and a few others I'm working on. These are things I use often so prototyping them seem to make sense. I was planning on making a set of these that I can include at the start of all my movies that need them.
-
 Originally Posted by blanius
Maybe it would be better to use a setInterval funtcion instead.
That might be a good choise.
-
KoolMoves Moderator
Ok this is what I've got now but it doesn't work I imagine I'm thinking it out wrong.
Code:
MovieClip.prototype.fadeUp=function(){
this.doFade=function(){
if (this._alpha<100){
this._alpha+=10;
}
if (this._alpha>=100){
clearInterval(this.intervalID);
}
}//end do fade function
this.intervalID=setInterval(doFade,50);
}//end
-
Try this
Code:
this.intervalID = setInterval(this,'doFade',50);
-
KoolMoves Moderator
This is working great.. one more question though. If I try to have both fadeUp and fadeDown functions only fadeUp seems to work.
Code:
MovieClip.prototype.fadeDown=function(){
this.doFade=function(){
if (this._alpha>0){
this._alpha-=10;
}//end if
if (this._alpha<=0){
clearInterval(this.intervalID);
}
}//end do
this.intervalID=setInterval(this,'dofade',50);
}//end
MovieClip.prototype.fadeUp=function(){
this.doFade=function(){
if (this._alpha<100){
this._alpha+=10;
}
if (this._alpha>=100){
clearInterval(this.intervalID);
}
}//end do fade function
this.intervalID=setInterval(this,'doFade',50);
}//end
-
The fadeDown function works for me. 
Here's another code example I just created. It addes two properties to a movieclip. _alphastep and _2alpha. When you set a value to _2alpha it will automatically fade to that alpha value. _alphastep controls the speed.
Code:
// declare local variables g and s
var g,s;
// add $fnInterval internal function
MovieClip.prototype.$fnInterval = function(){
if (this.$2alpha > this._alpha){
this._alpha = Math.min(this._alpha + this.$alphastep, this.$2alpha);
} else {
this._alpha = Math.max(this._alpha - this.$alphastep, this.$2alpha);
}
if (this.$2alpha == this._alpha){
clearInterval(this.$iID);
this.$iID = null;
}
}
// implement _alphastep property
g = function(){ return this.$alphastep; }
s = function(v){ this.$alphastep = Math.max(0.1,Math.min(v,100)); }
MovieClip.prototype.addProperty('_alphastep',g,s);
// set an initial value for _alphastep
MovieClip.prototype.$alphastep = 5;
// implement _2alpha property
g = function(){ return this.$2alpha; }
s = function(v){
this.$2alpha = Math.max(0,Math.min(v,100));
if (!this.$iID){
this.$iID = setInterval(this,'$fnInterval',40);
}
}
MovieClip.prototype.addProperty('_2alpha',g,s);
// delete local variables g and s
delete g;
delete s;
// test the code assuming you have 2 movieclips
// named mc1 and mc2
mc1._alphastep = 1;
mc1._2alpha = 60;
mc2._alphastep = 3;
mc2._2alpha = 10;
Last edited by w.brants; 08-23-2006 at 12:10 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|