I have a FLV player with standard controls. I have also made another play buttons that sits ontop of the video until it starts playing.
vidPlayer.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hidePlaybtn);
//when you click the play button I made it calls startVid
function startVid(e:MouseEvent):void
{
vidPlayer.play();
hidePlaybtn(null);
}
function hidePlaybtn(e:VideoEvent):void
{
TweenLite.to(playBtn,1,{autoAlpha:0,ease:Exponential.easeOut});
}
my problem was, in the startVid function I call hidePlaybtn(). I first had it like hidePlaybtn() and it was giving me an error because hidePlaybtn() is expecting a VideoEvent. So I just put null in their and it worked fine. I never really used null before, but is that ok what I did or is their a more proper way of doing it?
Null is exactly what it sounds like, it’s nothing. In your example, it needed a parameter (usually an event) - so you passed it null, which appeased the compilers check for the right number of arguments. Since you’re not actually using the argument, it didn’t cause any problems. If you’d had something like e.target in your code, you’d have gotten a #1009 error.
If you try to use it you’ll get a #1009 error, but if you’re just using it as an optional parameter without actually accessing the object, it will work fine.
In the context of default arguments, if you have a function declaration like:
function func(mySprite:Sprite = null): void {}
…then calling “func(someSpriteInstance)” definitely won’t delete the Sprite, although I don’t think that that’s what you meant, since nothing that has something to do with default arguments being null has anything directly to do with whether or not a Sprite gets deleted, really.
Anyway, if you are simply referring to a situation in which you have a declared variable that holds a Sprite reference, then no, executing the statement “myVariable = null” will not delete the Sprite since Flash has a garbage collector instead of any user-controllable memory management. Also, here is a relevant portion of a comment that I made in a thread earlier today, if it helps:
[quote=Krilnon;2337756]When you declare a variable inside of a function, the variable is destroyed when the function finished executing. If you assign a reference to that variable, like “var o:Object = new Object()” and never let any other variable hold a reference to the object, then o will become eligible for garbage collection. For example, if you had an instance variable in your class named obj and it was declared in the class instance’s $cinit function (just after the “public class X {” brace, or somewhere directly in that scope), which is special and doesn’t let variables expire at the end of the call, and you assigned o’s reference to obj (“obj = o”), then there would be another variable that holds a reference to the object that you created. That variable isn’t destroyed, so the garbage collector won’t get rid of your object.
[/quote]