Re: [flexcoders] Re: Calling static function on Class instance
Going back to my project the [functionName] does not work still. the class reference points to a class that extends a base class. The static function is in the base class. Is that why it doesn't work? Thanks On Thu, May 15, 2008 at 8:24 AM, Giles Roadnight [EMAIL PROTECTED] wrote: Thanks Gordon. I got your code to run fine but when I try c.Roadnight() outside the class I still get a compiler error. c[Roadnight works](); I have attached a zip of the project. The compiler error line is commented out. On Wed, May 14, 2008 at 6:56 PM, Gordon Smith [EMAIL PROTECTED] wrote: 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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Giles Roadnight *Sent:* Wednesday, May 14, 2008 1:03 AM *To:* flexcoders@yahoogroups.com *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] 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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Giles Roadnight *Sent:* Tuesday, May 13, 2008 8:44 AM *To:* flexcoders@yahoogroups.com *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] 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 -- Giles Roadnight http://giles.roadnight.name -- Giles Roadnight http://giles.roadnight.name -- Giles Roadnight http://giles.roadnight.name -- Giles Roadnight http://giles.roadnight.name
RE: [flexcoders] Re: Calling static function on Class instance
Yes. Static are not inherited so you have to find the base class that has the static function. describeType or getQualifiedSuperClassname() From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Giles Roadnight Sent: Thursday, May 15, 2008 12:29 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Re: Calling static function on Class instance Going back to my project the [functionName] does not work still. the class reference points to a class that extends a base class. The static function is in the base class. Is that why it doesn't work? Thanks On Thu, May 15, 2008 at 8:24 AM, Giles Roadnight [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Thanks Gordon. I got your code to run fine but when I try c.Roadnight() outside the class I still get a compiler error. c[Roadnight works](); I have attached a zip of the project. The compiler error line is commented out. On Wed, May 14, 2008 at 6:56 PM, Gordon Smith [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: 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: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com ] On Behalf Of Giles Roadnight Sent: Wednesday, May 14, 2008 1:03 AM To: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com 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: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com ] On Behalf Of Giles Roadnight Sent: Tuesday, May 13, 2008 8:44 AM To: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com 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 -- Giles Roadnight http://giles.roadnight.name http://giles.roadnight.name -- Giles Roadnight
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] 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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Giles Roadnight *Sent:* Tuesday, May 13, 2008 8:44 AM *To:* flexcoders@yahoogroups.com *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] 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 -- Giles Roadnight http://giles.roadnight.name -- Giles Roadnight http://giles.roadnight.name
RE: [flexcoders] Re: Calling static function on Class instance
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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Giles Roadnight Sent: Wednesday, May 14, 2008 1:03 AM To: flexcoders@yahoogroups.com 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: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com ] On Behalf Of Giles Roadnight Sent: Tuesday, May 13, 2008 8:44 AM To: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com 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
RE: [flexcoders] Re: Calling static function on Class instance
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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Giles Roadnight Sent: Tuesday, May 13, 2008 8:44 AM To: flexcoders@yahoogroups.com 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
RE: [flexcoders] Re: Calling static function on Class instance
Create an instance of the class and call getQualifiedClassName() on it. Or use describeType() on the Class object. The former is probably faster. Gordon Smith Adobe Flex SDK Team From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Giles Roadnight Sent: Tuesday, May 13, 2008 8:44 AM To: flexcoders@yahoogroups.com 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