Problems to copy a component in the library

:sigh:

hi guys,

ive got on little problem in flash mx

ive got one component (image fader button)–> from flashcomponents.net

When you put one component (image fader ) in the library and then you try to copy this one in the library ,the one that was copied loses all the fading functions of the original (all the script stays the same ,but the copied one is not working right like the original,dont know what im doing wrong could somebody help me? is it a bug?

:q:

Well if I remember correctly, after installing the .mxp file for putting the component in manuall all you have to do is press F11 on the keyboard to open the component panel, then select your component and drag an instance of it from the window onto the object you want (in this case the image to fade).

So there is no reason to copy it in the library.

And well, I am a bit bored right now, so I wrote up another alternative.

You can also use prototypes to do this instead of components. Add these actions to a frame (usually frame 1)…

MovieClip.prototype.fader = function(speed, minAlpha, maxAlpha) {
	this._alpha = minAlpha;
	this.onRollOver = function() {
		this.onEnterFrame = function() {
			this._alpha += speed;
			if (this._alpha>=maxAlpha) {
				this._alpha = maxAlpha;
				delete this.onEnterFrame;
			}
		};
	};
	this.onRollOut = function() {
		this.onEnterFrame = function() {
			this._alpha -= speed;
			if (this._alpha<=minAlpha) {
				this._alpha = minAlpha;
				delete this.onEnterFrame;
			}
		};
	};
};

Now right click on a movie clip symbol, and open the actions panel and add this code to the movie clip…

onClipEvent (load) {
	this.fader(5, 30, 100);
}

The prototype is fader(speed, minAlpha, maxAlpha)

So in the above usage code 5 is the speed, 30 is the minimun alpha number and 100 is the maximum alpha number.

the problem is i want to use this fader image thing to create buttons with a fade,and when i try to apply a mouse event on them it does not work!!!

it only works in the component script when i change the mouse on events,but i only can change them one time,thats why i wanted to copy this component in the library to make more components as buttons with fades but it does not work that way and i dont know how to do it

Well if you use the prototype method I supplied above, you can use your movie clip as a button so the actions on your movie clip would be lik…

onClipEvent (load) {
	this.fader(5, 10, 70);
}
on (release) {
	//do this
}

Where //do this is where the code for what you want your button to do goes.

thx a lot,i worx

greetings

wafze:beam:

No problem man, glad I could help :beam:

Wait Wait!!! I noticed a bug in my script.

It seems that if the user clicks on the button, but drags the mouse off of the button then it stays dark and you have to roll back over and then off again for it to fade back to the original alpha.

So I updated my code, and this should fix the issue

MovieClip.prototype.fader = function(speed, minAlpha, maxAlpha) {
	this._alpha = minAlpha;
	this.onRollOver = function() {
		this.onEnterFrame = function() {
			this._alpha += speed;
			if (this._alpha>=maxAlpha) {
				this._alpha = maxAlpha;
				delete this.onEnterFrame;
			}
		};
	};
	this.onRollOut = this.onDragOut=function () {
		this.onEnterFrame = function() {
			this._alpha -= speed;
			if (this._alpha<=minAlpha) {
				this._alpha = minAlpha;
				delete this.onEnterFrame;
			}
		};
	};
};

I hadded a this.onDragOut to detect when the mouse is being dragged off of the clip instead of just rolling off.

If there is any part of this script you need explained, you can ask. I won’t be around much in the next day or two, but if no one else answers by the time I get back here, I can answer when I come back.

And if you want it to stay dark until the user release the mouse (even outside the clip) instead of fading when the user drags off of it you can replace this.onDragOut with this.onReleaseOutside

hey man… i was just browsing through the stuff here and found this very useful…

thank you!

No problem ivcho, I am glad you found this useful :slight_smile:

If you need any part of it explained, don’t be afraid to ask, I will do my best to explain it.