Copy link to clipboard
Copied
hi
I am developing a game using MVC. In which i need to send mulitple parameter to the addEventListener. So i have created a customEvent class with a parameter as object type.
Below is code flow
my custom Event class:
public function CustomEvent(type:String, customData:Object = null,bubbles:Boolean=false,cancelable:Boolean=false) {
//constructor
super(type,bubbles,cancelable);
this.customData = customData;
}
Adding listener
_myController.addEventListener(CustomEvent.UPDATE_MY_METHOD, doSomething);
function doSomething(myObj:Object){
var param1 = myObj.param1;
var param2 = myObj.param2 ;
var param3 = myObj.param2 ;
}
To call my custom event.
var dispObj = new Object();
dispObj.param1 = "ONE";
dispObj.param2 = 100;
dispObj.param3 = "PLAYER";
dispatchEvent(new CustomEvent(CustomEvent.UPDATE_MY_METHOD, dispObj);
This idea makes me to use more objects in my game.
Now my doubt is, whether this will leads to memory leakage or any other performance issue? If it is can I replace dictionary object or any other best option.
Any suggestions? Please.
Thanks in advance
there won't be a memory issue because those customevent's will get gc'd. but there is more work for the flash player because there's more to gc.
on the other hand, you have to use something to communicate needed parameters so i don't see a benefit to using getters or other public functions that allow parameter values to be retrieved.
Copy link to clipboard
Copied
there won't be a memory issue because those customevent's will get gc'd. but there is more work for the flash player because there's more to gc.
on the other hand, you have to use something to communicate needed parameters so i don't see a benefit to using getters or other public functions that allow parameter values to be retrieved.
Copy link to clipboard
Copied
You actually can get a performance issue because of creating so many objects that subsequently need to be garbage collected. However, you'd need to be creating huge numbers of them. Here are some alternatives:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now