Or, thinking about it, you could catch the reference error in a
try/catch block. It's more of a kludge, but might give you much higher
performance!

Ian

On Tue, Oct 28, 2008 at 8:33 AM, Ian Thomas <[EMAIL PROTECTED]> wrote:
> I'm afraid I don't think either Han's or Steven's solutions work in
> AS3 - you'd still get a ReferenceError (unless currentSection is
> dynamic).
>
> I'd do it using flash.utils.describeType, like so:
>
> import flash.utils.describeType;
>
> :
>
> var desc:XML=flash.utils.describeType(currentSection);
>
> if (desct.method.(@name=="refresh").length()>0)
> {
>        currentSection['refresh']();  /// Still need bracket access here, as
> otherwise compilation will fail
> }
>
> Wrapping it up, here's a method-checking function:
>
> function methodExists(obj:Object,name:String):Boolean
> {
>        var desc:XML=flash.utils.describeType(obj);
>        return (desc.method.(@name==name).length()>0);
> }
>
> (and here, for free, is one for properties:
> function propertyExists(obj:Object,name:String):Boolean
> {
>        var desc:XML=flash.utils.describeType(obj);
>        return (desc.accessor.(@name==name).length()>0);
> }
> )
>
> It's heavyweight, though. If anyone can find a better solution...
>
> Ian
>
> On Tue, Oct 28, 2008 at 2:09 AM, Steven Sacks <[EMAIL PROTECTED]> wrote:
>> if (currentSection.refresh)
>> {
>>    currentSection.refresh();
>> }
>>
>> Karim Beyrouti wrote:
>>>
>>> Hello Group -
>>> This should be really easy. I am trying to find out how to check if a
>>> function exists or not in AS3 - I tried this:
>>> <code>
>>>        If ( currentSection.refresh != null ) {
>>>                currentSection.refresh();
>>>        }
>>>
>>>
>>> </code>
>>>
>>> But I get "ReferenceError: Error #1069: Property refresh not found" when
>>> the
>>> function does not exist.
>>>
>>> Any clues?
>>>
>>>
>>> Kind Regards
>>>
>>>
>>>
>>> Karim
>>>
>>> _______________________________________________
>>> Flashcoders mailing list
>>> [email protected]
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>> _______________________________________________
>> Flashcoders mailing list
>> [email protected]
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to