Copy link to clipboard
Copied
Hi Everyone, sorry for posting so many beginners questions in the last few days...,
Whats wrong with this code?
function fadeOUT(e:String):void
{
this
this
if (this
{
this
trace("fire")
}
}
fadeOUT("McInstanceName");
If the code is like this i get an "
TypeError: Error #1010: A term is undefined and has no properties.
at Test87_fla::MainTimeline/fadeOUT()"
Here is the Part i don't understand: The code does not produce Errors if i do one of the following:
Is there maybe another way to pass a movieClip into a function?
I would appreciate any help, thanks
You're calling fadeOut(needs a string) back to itself as fadeOut(needs an Event). Make it be two functions, say one is startFadeOut(e:String) that would apply the listener, and then fadeOut(e:Event) that does the enterframe alpha change.
Copy link to clipboard
Copied
You're calling fadeOut(needs a string) back to itself as fadeOut(needs an Event). Make it be two functions, say one is startFadeOut(e:String) that would apply the listener, and then fadeOut(e:Event) that does the enterframe alpha change.
Copy link to clipboard
Copied
Thanks Colin! I LOVE this Community!
Copy link to clipboard
Copied
Follow up question:
my code now produces the same error.
If i do not pass a String into fadeOUT(), how can i specify, which Movie Clip Instance i want the alpha change applied to?
I fear, i am too stupid for AS3...
function StartFadeOUT(e:String):void
{
this
}
function fadeOUT(e:Event):void
{
this
if (this
{
this
}
}
StartFadeOUT("McInstanceName");
Copy link to clipboard
Copied
I feel sure there may be a better way to organize the code. But for now, try:
function fadeOUT(e:Event):void
{
this
Copy link to clipboard
Copied
That should have been:
function fadeOUT(e:Event):void
{
e.target.alpha -= 0.1;
Copy link to clipboard
Copied
Thanks Colin,
if i just change this
if i comment out the if statement, alpha goes instantly to 0, without fading or me ever seeing the specified MC...
Copy link to clipboard
Copied
Scratch the last comment,
the following code seems to work:
function fadeOUT(e:Event):void
{
e.target.alpha -= 0.01;
if (e.target.alpha <= 0)
{
e.target..removeEventListener(Event.ENTER_FRAME, fadeOUT);
trace("fire")
}
}
notice, i changed 0.1 to 0.01? Any idea, why it would fade out much more quickly now?
Thanks again
Copy link to clipboard
Copied
Sigh. Seriously, you're Doing It Wrong. Ditch the event listener entirely and use the Tween class instead. It's one line of code. ONE.
I realize you're emotionally invested in making your original approach work, but there's no room for sentiment in coding.
Copy link to clipboard
Copied
OK, i had a look at the documentation of the tween class. If you tell me which ONE line of code that would be, i'll use it. Say i have 3 MovieClips MC1, MC2 and MC3, and i want to fade in MC3 and fade the currently visible one out, no matter which MC is currently visible. What would that one line of code look like? Say, i want to add MC4,5,6,7, and 8 afterwards. If you cannot/ do not want to provide that ONE line of code, then i'll use the approach i worked out with the help of Colin Holgate. You may be right that there is no room for sentiment in coding, but as a novice i learned very much about AS3 and coding in general by my own approach.
I'll even unmark Collins answer as correct and yours as correct if you provide that ONE line of code (provided it does work for me).
Thanks and kind regards
Copy link to clipboard
Copied
If all you want to do is fade something out, why aren't you just using the Tween class? It would be so much simpler.
Copy link to clipboard
Copied
Hi, Clay, thanks for your reply,
if you would explain to me, what a "Tween Class" is and how i would use it, i would very much appreciate it. I just started using Animate a week ago...
Copy link to clipboard
Copied
Tween - Adobe ActionScript® 3 (AS3 Flash) API Reference
import fl.transitions.Tween;
import fl.transitions.easing.None;
new Tween(McInstanceName, "alpha", None.easeNone, 1, 0, 10);
Copy link to clipboard
Copied
ClayUUID Thanks i'll have a look at that.
In the End i want to have a method that Fades Every MC in an array out, while fading only the specified MC in...