Other Sites in the News
- November 13, 2024
- Types of Technology: A Complete Overview [2025] - Simplilearn
Why can't I access "relatedObject"?
I'm just trying to see if the function was called because of a field blur or button press, so I can ignore some code in case of the later:
var ignore:Boolean = false;
if(evt.relatedObject.id == 'btnReset'){
ignore = true;
}
if(evt.relatedObject.id == 'btnReset'){
ignore = true;
}
Why does the compiler complain "Access of possibly undefined property relatedObject through a reference with static type flash.events:Event" ? Wrong event type? Missing import?
I don't know, it won't compile, even though you can set a breakpoint and see the relatedObject listed in the variables within the event.
No time to care. So I smush it into a core object and use that instead:
var ignore:Boolean = false;
// won't compile using a native reference to evt.relatedObject
// so convert to a plain object
var thisObj:Object = evt;
// call me paranoid
if (evt.relatedObject != null && thisObj.relatedObject.id != null){
if(thisObj.relatedObject.id == 'btnReset'){
ignore = true;
}
}
// won't compile using a native reference to evt.relatedObject
// so convert to a plain object
var thisObj:Object = evt;
// call me paranoid
if (evt.relatedObject != null && thisObj.relatedObject.id != null){
if(thisObj.relatedObject.id == 'btnReset'){
ignore = true;
}
}