I have a function in my flash AS3 file. I’d like to pass a parameter when calling this function and have that parameter become the name of a new FLV playback component I’m declaring;
function newVideo(myVideoName){
var [myVideoName]:FLVPlayback = new FLVPlayback();
}
—
edit – I now have the following code. How would I add the FLV playback component to the stage?
> function newVideo(myVideoName:String):FLVPlayback {
>
> var flvP:FLVPlayback = new FLVPlayback();
> flvP.name = myVideoName;
flvP.source = "argentinaTrailer.f4v";
> return flvP;
}
>
> var myPlayer:FLVPlayback = newVideo('player1');
What you are doing here is not allowed. The notation for creating and accessing objects using a string reference (
this['someObject']) does not permit you to cast a type. Furthermore, objects created in this fashion cannot then be directly accessed using that name without using the identifier notation:and
So, to make your function work it should be written:
but you will only then be able to access the player by using that same string reference, like this:
Furthermore, none of the above is giving the instance of the FLVPlayback component a name. What it is doing is defining the name of a reference to your FLVPlayback. If you are intending to create an FLVPlayback that has an instance name of
myVideoNamethen you should create a function that looks like this:What this does is creates a new instance of the FLVPlayback component, assigns it an instance name, and returns a reference to it. You would use it like this: