Method Verification in Actionscript 3
ReferenceError: Error #1069: Property doSomething not found on YourObject and there is no default value.
Look familiar?
Let’s say you want to verify an object has a method before calling that method - so flash won’t do something it shouldn’t and return a runtime error and CRASH.
SOLUTION:
{
if(object.hasOwnProperty(methodName)) return object[methodName] is Function;
return false;
}
var s:Sprite = new Sprite();
trace(“globaLToLocal is a method: “+isMethod(s, “globalToLocal”));
trace(“x is a method: “+isMethod(s, “x”));
// s would now, in fact, NOT do something.
if(isMethod(s, “doSomething”)) s.doSomething();
About this entry
You’re currently hearting “Method Verification in Actionscript 3,” an entry on I h♥rt actionscript.
- written:
- 03.28.10 / 4pm
- category:
- AS3

No comments
Jump to comment form | comments rss [?] | trackback uri [?]