Alex meant c.Roadnight() or c["Roadnight"]() if you want to call the
static function. Without the () you get a reference to the function,
rather than the result produced by calling the function.
Here is a complete and tested ActionScript app which illustrates four
ways to call a static function on a Class object. It outputs "Roadnight"
four times.
package
{
import flash.display.Sprite;
public class Giles extends Sprite
{
public function Giles()
{
super();
var c:Class = Giles;
c.Roadnight();
c["Roadnight"]();
var f:Function;
f = c.Roadnight;
f();
f = c["Roadnight"];
f();
}
public static function Roadnight():void
{
trace("Roadnight");
}
}
}
Gordon Smith
Adobe Flex SDK Team
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Giles Roadnight
Sent: Wednesday, May 14, 2008 1:03 AM
To: [email protected]
Subject: Re: [flexcoders] Re: Calling static function on Class instance
Many thanks for the replies, describeType works great.
I can't get c.Roadnight to work though and for now am having to create
an instance of the class to call the function (which I had to make
non-static).
var selectedTemplateClass:Class = initEvent.frameType;
var xml:XML = selectedTemplateClass.getBlankXML();
gives a compiler error.
var selectedTemplateClass:Class = initEvent.frameType;
var xml:XML = selectedTemplateClass.getBlankXML;
does not give a compiler error but xml remains null
I also tried
var selectedTemplateClass:Class = initEvent.frameType;
var blankXMLFunction:Function =
selectedTemplateClass.getBlankXML;
var xml:XML = blankXMLFunction();
but blankXMLFunction remains null.
At the moment I have it working with a fresh instance of the class but
I'd rather not do it this way if possible.
Thanks
Giles
On Tue, May 13, 2008 at 6:32 PM, Alex Harui <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:
You mean you have:
pulbic class Giles
{
public static function Roadnight():void
{
}
}
And
var c:Class = Giles;
If so it is just just be c.Roadnight or c["RoadNight"]
________________________________
From: [email protected] <mailto:[email protected]>
[mailto:[email protected] <mailto:[email protected]> ]
On Behalf Of Giles Roadnight
Sent: Tuesday, May 13, 2008 8:44 AM
To: [email protected] <mailto:[email protected]>
Subject: [flexcoders] Re: Calling static function on Class instance
Along the same lines - how do I get the class name from a Class object.
If I do toString() I get [class HeaderImage1]. Do I just have to extract
the string from that?
Thanks again
Giles
On Tue, May 13, 2008 at 4:21 PM, Giles Roadnight <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:
Hi All
I have a class (BaseTemplate) that is extended to become lots of
different Template classes.
I have a list class that takes an array of Class objects to allow a user
to select a template (the renderer creates an instance of the class).
When I click an item in the list I want to call a static function on the
Template.
When I have a Class object is there anyway of calling a static function
on that class without creating an instance of the class?
Thanks
--
Giles Roadnight
http://giles.roadnight.name <http://giles.roadnight.name>
--
Giles Roadnight
http://giles.roadnight.name <http://giles.roadnight.name>
--
Giles Roadnight
http://giles.roadnight.name <http://giles.roadnight.name>