Trying to understand the function

I am trying to tweak a function that I found on the internet. I know what the function does. It receives information about the webcam on your computer and publishes it in a text article,

But the separate line got a little confused.

Any help?

thank

private var camera:Camera;
private function list_change(evt:ListEvent):void {
var tList:List = evt.currentTarget as List;
var cameraName:String = tList.selectedIndex.toString();
camera = Camera.getCamera(cameraName);
textArea.text = ObjectUtil.toString(camera);
}

      

+3


source to share


1 answer


private var camera:Camera;

      

This line creates a variable of type Camera. It doesn't instantiate a variable.

private function list_change(evt:ListEvent):void {

      

This line is the standard function header. Since the argument is ListEvent, it makes me think that this function is probably written as an event handler. Because of the name of the function, this is most like listening for a list change event.

var tList:List = evt.currentTarget as List;

      

This line creates a link to the list that dispatched the event that caused this handler to execute.

var cameraName:String = tList.selectedIndex.toString();

      



This string will convert selectedIndex to string. It's a bit weird to convert the index to a string and not some value. But the reason they do looks like on the next line.

camera = Camera.getCamera(cameraName);

      

This camera variable (defined in line 1) is used and actually gets the camera instance. It uses a "camera name", which makes it seem to me that the list that sent this change event contains a list of cameras available on the system.

textArea.text = ObjectUtil.toString(camera);

      

This converts the camera object to a string and displays it in the text area. You usually don't try to do this because you don't provide any valuable data. Object by default will render strings as [Object Object] or something similar. Perhaps the camera object has its own string function; I have no experience with this. You usually want to access the properties of an object to get useful information, rather than try it on the object itself.

}

      

This line is the end of the function. The open parenthesis was on the second line of code in the function definition.

+7


source







All Articles