Hi, I have small syntax issue
I have four NetStream objects that receive cuepoints from different videos. I’d like to define one function for them all instead of using four inline functions and I’m stuck with syntax
Here’s the code:
ns1.onCuePoint = callCuePoint;
ns2.onCuePoint = callCuePoint;
ns3.onCuePoint = callCuePoint;
ns4.onCuePoint = callCuePoint;
function callCuePoint(infoObject:Object):void {
trace(infoObject)
}
This works fine, but what if I want to pass additional parameter (ID) to callCuePoint function?
I tried calling it using:
ns1.onCuePoint = callCuePoint("video1")
Which works, but obviously I loose the infoObject. Can anyone help me with this. How can I call the callCuePoint function with both - InfoObject and ID
thanks for help
you can do it in many ways…
Pass different variables for each argument
function myfunction(arg1,arg2,arg3){
trace(arg1+" “+arg2+” "+arg3);
}
myfunction(“hello”,“my name is”,“pier”);
Pass an object:
function myfunction(args_object){
trace(args_object.name); //gives Pier
}
my_object.name = “Pier”
myfunction(my_object);
Or pass an array
cars_array[0] = “Ford”
function myfunction(array){
trace(array[0]); //that gives ford
}
myfunction(my_array);
Hell I think you can even pass a function…
I know all of these, but perhaps I didn’t explain my problem correctly.
The onCuePoint event handler requires one parameter which is called infoObject. My question is, how can I pass another parameter to the onCuePoint event handler. As soon as I call it using any of the methods described above, I loose the infoObject object which I need to successfuly process the video.
Have you thought about using the built-in arguments array with your function?
arguments
Object
|
±arguments
public class arguments
extends Object
An arguments object is used to store and access a function’s arguments. While inside the function’s body it can be accessed with the local arguments variable.
The arguments are stored as array elements, the first is accessed as arguments[0], the second as arguments[1], etc. The arguments.length property indicates the number of arguments passed to the function. Note that there may be a different number of arguments passed in than the function declares.
Availability: ActionScript 1.0; Flash Player 5 - As of Flash Player 6 the arguments object supports all methods and properties of the Array class.
Check out “arguments” in the Help files.
That’s great idea, I totally forgot that arguments can be addresed through this class.
Anyways I temporarily solved this by adding new property to NetStream which I can check from my generic function with this keyword
Thanks for help:)