Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for(var i:Number; i < 10; i++){
- var someVar = i;
- myClips[i].addEventListener(MouseEvent.CLICK, doSomething);
- }
- function doSomething(e:MouseEvent){ /* */ }
- for(var i:Number; i < 10; i++){
- var someVar = i;
- myClips[i].addEventListener(MouseEvent.CLICK, function(){
- doSomething(someVar);
- });
- }
- function doSomething(index){ trace(index); }
- public class MyClip
- {
- public var myPublicProperty:int;
- public function MyClip() { //... }
- }
- for (var i:int = 0; i < 10; i++)
- {
- myClips[i].myPublicProperty = i;
- myClips[i].addEventListener(MouseEvent.CLICK, doSomething);
- }
- function doSomething(event:MouseEvent):void
- {
- trace(event.currentTarget.myPublicProperty.toString());
- }
- import flash.events.Event;
- //custom event class to enable the passing of strings along with the actual event
- public class TestEvent extends Event
- {
- public static const TYPE1 :String = "type1";
- public static const TYPE2 :String = "type2";
- public static const TYPE3 :String = "type3";
- public var parameterText:String;
- public function TestEvent (type:String, searchText:String)
- {
- this.parameterText = searchText;
- super(type);
- }
- }
- dispatchEvent(new TestEvent(TestEvent.TYPE1, 'thisIsTheParameterText'))" ;
- someComponent.addEventListener(TestEvent.TYPE1, listenerFunction, true , 0, true);
- for (var i=0; i<5; i++) {
- myClips[i].addEventListener( MouseEvent.CLICK, getHandler(i) );
- }
- function getHandler(i) {
- return function( e:MouseEvent ) {
- test(i);
- }
- }
- function test( j ) {
- trace("foo "+j);
- }
- private function myCallbackFunction(e:Event, parameter:String):void
- {
- //voila, here's your parameter
- }
- private function addArguments(method:Function, additionalArguments:Array):Function
- {
- return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
- }
- var parameter:String = "A sentence I want to pass along";
- movieClip.addEventListener(Event.COMPLETE, addArguments(myCallbackFunction, [parameter] ) );
- var view:Object=[];
- for(var i:uint=0;i<Camera.names.length;i++){
- view[i]=getChildByName("Cam"+i);
- //_________ Add Text _________
- var tf:TextField = new TextField();
- tf.autoSize = TextFieldAutoSize.LEFT;
- tf.textColor=0xffffff;
- view[i].tf=view[i].addChild(tf);
- //_________ Add Timer _________
- var t:Timer = new Timer(1000);
- view[i].timer=t;
- view[i].timer.start();
- view[i].timer.addEventListener(TimerEvent.TIMER, addArg(i));
- }
- function addArg(adi:uint):Function {
- return function(event:TimerEvent):void {
- updatecamstatus(adi);
- }
- }
- function updatecamstatus(vH:uint):void {
- with (view[vH]){
- tf.text="Cam" + vH + "n";
- tf.appendText("activityLevel: " + videosource.activityLevel + "n");
- tf.appendText("motionLevel: " + videosource.motionLevel + "n");
- }
- }
Add Comment
Please, Sign In to add comment