In as3, adding a listener can pass parameters in a simple way.
For example, column1.addeventlistener (mouseevent. mouse_over,Function (E: mouseevent) {onmouseoverevent (E, subrisk. Days );}); // Tips on parameters passing through the listener Method
Private function onmouseoverevent (E: mouseevent, STR: string): void {lablecon. X = E. stagex; lablecon. y = E. stagey; lablecon. TEXT = "value:" + STR ;}
Problem: simple static constants can be passed in this way, but in the following case, there will be problems to be solved...
For each (VAR subrisk: XML in xmlrisk. area) {trace (subrisk .. @ display + "---" + subrisk. days); // generate the UI var UI: zhangui = new zhangui (); var column1: Label = UI. createlableback (164 + I * 13,124, subrisk. daylevel); var columnnum: Label = UI. createlablebacknum (150 + I * 13,200, subrisk. ID );//?????????????????? Is there a problem with the value passed in the listener ?? Subrisk. Days cannot use variables, but I still don't know how to solve them.Column1.addeventlistener (mouseevent. mouse_over, function (E: mouseevent) {onmouseoverevent (E, subrisk. days) ;}); // tips on parameters passing through the listener method column1.addeventlistener (mouseevent. mouse_out, onmouseoutevent); this. addelement (column1); If (subrisk .. @ display = "true") {This. addelement (columnnum);} I ++ ;}
The input parameter value of the listener is a constant.