You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Deepak MS <me...@gmail.com> on 2013/08/16 13:39:12 UTC

How to get a class instance using string name?

Hi there,

Is there a way we can get a running instance in our application, by using
it’s id as a String?



For ex:

I have a mxml line which is

<mx:LinearAxis id="vAxis1"  title="Growth%"
labelFunction="percentageformatAxis"  />





There is a data xml in which these instance names (vAxis1, vAxis2 …) shall
be declared:



<doc>


<row metricId="1" metricName="AUD" attribute="@AUD" checked="1"
chartType="1" verticalAxis="vAxis1">


<row metricId="2" metricName="AUD Growth %" attribute="@AUDGrowth"
checked="1" chartType="2" verticalAxis="vAxis2"/>


</row>


<row metricId="3" metricName="AUD MS" attribute="@AUDMSPerc" checked="0"
chartType="2" verticalAxis="vAxis3">


                <row metricId="4" metricName="AUD MS Growth %"
attribute="@AUDMSGrowth" checked="0" chartType="1" verticalAxis="vAxis4"/>


</row>

                                                                </doc>



This data would be dynamic and I am trying to assign verticalAxis attribute
value to verticalAxis property of a column series at runtime:



colSeries = *new* ColumnSeries();

                                                colSeries.yField =
String(metric.@attribute);

                                                colSeries.displayName =
String(metric.@metricName);





                                                colSeries.verticalAxis =
metric.@verticalAxis; //metric.@verticalAxis here would be a string. But I
have to reference the LinearAxis that I have declared on top, which is
vAxis1.


            seriesArray.push(colSeries);



Is there any way we can achieve that?



getDefinitionByName() would just give be the class, but I need the declared
instance.





Warm regards,

Deepak

RE: How to get a class instance using string name?

Posted by Gordon Smith <go...@adobe.com>.
Doesn't myModelInstance.vAxis1 work? Every MXML file defines a class, and every tag with an id defines a property in that class, where the name of the property is specified by the id. So when you have an instance of that class, you should just be able to use the dot operator to access that property, in the same way that you would access a public var or public getter in the class.

- Gordon

-----Original Message-----
From: Deepak MS [mailto:megharajdeepak@gmail.com] 
Sent: Friday, August 16, 2013 5:17 AM
To: users@flex.apache.org
Subject: Re: How to get a class instance using string name?

To be precise, I was using linear axis in a model class, and i used myModelInstance["vAxis1"] and that worked. : ) That was simple concept but I kept banging my head with all types of combinations using  getDefinitionByName....getQualifiedClassName.....

Thanks for the help everyone...

Cheers!


On Fri, Aug 16, 2013 at 5:23 PM, Jitendra Jain < warriorofheavenster@gmail.com> wrote:

> you can use myComponentName["myView"] where myComponentName is the 
> parent one and myView is the child
>
>
> On Fri, Aug 16, 2013 at 5:09 PM, Deepak MS <me...@gmail.com>
> wrote:
>
> > Hi there,
> >
> > Is there a way we can get a running instance in our application, by 
> > using it's id as a String?
> >
> >
> >
> > For ex:
> >
> > I have a mxml line which is
> >
> > <mx:LinearAxis id="vAxis1"  title="Growth%"
> > labelFunction="percentageformatAxis"  />
> >
> >
> >
> >
> >
> > There is a data xml in which these instance names (vAxis1, vAxis2 ...)
> shall
> > be declared:
> >
> >
> >
> > <doc>
> >
> >
> > <row metricId="1" metricName="AUD" attribute="@AUD" checked="1"
> > chartType="1" verticalAxis="vAxis1">
> >
> >
> > <row metricId="2" metricName="AUD Growth %" attribute="@AUDGrowth"
> > checked="1" chartType="2" verticalAxis="vAxis2"/>
> >
> >
> > </row>
> >
> >
> > <row metricId="3" metricName="AUD MS" attribute="@AUDMSPerc" checked="0"
> > chartType="2" verticalAxis="vAxis3">
> >
> >
> >                 <row metricId="4" metricName="AUD MS Growth %"
> > attribute="@AUDMSGrowth" checked="0" chartType="1"
> verticalAxis="vAxis4"/>
> >
> >
> > </row>
> >
> >                                                                 
> > </doc>
> >
> >
> >
> > This data would be dynamic and I am trying to assign verticalAxis
> attribute
> > value to verticalAxis property of a column series at runtime:
> >
> >
> >
> > colSeries = *new* ColumnSeries();
> >
> >                                                 colSeries.yField = 
> > String(metric.@attribute);
> >
> >                                                 
> > colSeries.displayName = String(metric.@metricName);
> >
> >
> >
> >
> >
> >                                                 
> > colSeries.verticalAxis = metric.@verticalAxis; //metric.@verticalAxis here would be a string.
> But I
> > have to reference the LinearAxis that I have declared on top, which 
> > is vAxis1.
> >
> >
> >             seriesArray.push(colSeries);
> >
> >
> >
> > Is there any way we can achieve that?
> >
> >
> >
> > getDefinitionByName() would just give be the class, but I need the
> declared
> > instance.
> >
> >
> >
> >
> >
> > Warm regards,
> >
> > Deepak
> >
>
>
>
> --
> Thanks and Regards,
> JJain,
>
>    If you have knowledge, let others light their candles in it 
> --Margaret
> Fuller:
>

Re: How to get a class instance using string name?

Posted by Deepak MS <me...@gmail.com>.
To be precise, I was using linear axis in a model class, and i used
myModelInstance["vAxis1"] and that worked. : )
That was simple concept but I kept banging my head with all types of
combinations using  getDefinitionByName....getQualifiedClassName.....

Thanks for the help everyone...

Cheers!


On Fri, Aug 16, 2013 at 5:23 PM, Jitendra Jain <
warriorofheavenster@gmail.com> wrote:

> you can use myComponentName["myView"] where myComponentName is the parent
> one and myView is the child
>
>
> On Fri, Aug 16, 2013 at 5:09 PM, Deepak MS <me...@gmail.com>
> wrote:
>
> > Hi there,
> >
> > Is there a way we can get a running instance in our application, by using
> > it’s id as a String?
> >
> >
> >
> > For ex:
> >
> > I have a mxml line which is
> >
> > <mx:LinearAxis id="vAxis1"  title="Growth%"
> > labelFunction="percentageformatAxis"  />
> >
> >
> >
> >
> >
> > There is a data xml in which these instance names (vAxis1, vAxis2 …)
> shall
> > be declared:
> >
> >
> >
> > <doc>
> >
> >
> > <row metricId="1" metricName="AUD" attribute="@AUD" checked="1"
> > chartType="1" verticalAxis="vAxis1">
> >
> >
> > <row metricId="2" metricName="AUD Growth %" attribute="@AUDGrowth"
> > checked="1" chartType="2" verticalAxis="vAxis2"/>
> >
> >
> > </row>
> >
> >
> > <row metricId="3" metricName="AUD MS" attribute="@AUDMSPerc" checked="0"
> > chartType="2" verticalAxis="vAxis3">
> >
> >
> >                 <row metricId="4" metricName="AUD MS Growth %"
> > attribute="@AUDMSGrowth" checked="0" chartType="1"
> verticalAxis="vAxis4"/>
> >
> >
> > </row>
> >
> >                                                                 </doc>
> >
> >
> >
> > This data would be dynamic and I am trying to assign verticalAxis
> attribute
> > value to verticalAxis property of a column series at runtime:
> >
> >
> >
> > colSeries = *new* ColumnSeries();
> >
> >                                                 colSeries.yField =
> > String(metric.@attribute);
> >
> >                                                 colSeries.displayName =
> > String(metric.@metricName);
> >
> >
> >
> >
> >
> >                                                 colSeries.verticalAxis =
> > metric.@verticalAxis; //metric.@verticalAxis here would be a string.
> But I
> > have to reference the LinearAxis that I have declared on top, which is
> > vAxis1.
> >
> >
> >             seriesArray.push(colSeries);
> >
> >
> >
> > Is there any way we can achieve that?
> >
> >
> >
> > getDefinitionByName() would just give be the class, but I need the
> declared
> > instance.
> >
> >
> >
> >
> >
> > Warm regards,
> >
> > Deepak
> >
>
>
>
> --
> Thanks and Regards,
> JJain,
>
>    If you have knowledge, let others light their candles in it --Margaret
> Fuller:
>

Re: How to get a class instance using string name?

Posted by Jitendra Jain <wa...@gmail.com>.
you can use myComponentName["myView"] where myComponentName is the parent
one and myView is the child


On Fri, Aug 16, 2013 at 5:09 PM, Deepak MS <me...@gmail.com> wrote:

> Hi there,
>
> Is there a way we can get a running instance in our application, by using
> it’s id as a String?
>
>
>
> For ex:
>
> I have a mxml line which is
>
> <mx:LinearAxis id="vAxis1"  title="Growth%"
> labelFunction="percentageformatAxis"  />
>
>
>
>
>
> There is a data xml in which these instance names (vAxis1, vAxis2 …) shall
> be declared:
>
>
>
> <doc>
>
>
> <row metricId="1" metricName="AUD" attribute="@AUD" checked="1"
> chartType="1" verticalAxis="vAxis1">
>
>
> <row metricId="2" metricName="AUD Growth %" attribute="@AUDGrowth"
> checked="1" chartType="2" verticalAxis="vAxis2"/>
>
>
> </row>
>
>
> <row metricId="3" metricName="AUD MS" attribute="@AUDMSPerc" checked="0"
> chartType="2" verticalAxis="vAxis3">
>
>
>                 <row metricId="4" metricName="AUD MS Growth %"
> attribute="@AUDMSGrowth" checked="0" chartType="1" verticalAxis="vAxis4"/>
>
>
> </row>
>
>                                                                 </doc>
>
>
>
> This data would be dynamic and I am trying to assign verticalAxis attribute
> value to verticalAxis property of a column series at runtime:
>
>
>
> colSeries = *new* ColumnSeries();
>
>                                                 colSeries.yField =
> String(metric.@attribute);
>
>                                                 colSeries.displayName =
> String(metric.@metricName);
>
>
>
>
>
>                                                 colSeries.verticalAxis =
> metric.@verticalAxis; //metric.@verticalAxis here would be a string. But I
> have to reference the LinearAxis that I have declared on top, which is
> vAxis1.
>
>
>             seriesArray.push(colSeries);
>
>
>
> Is there any way we can achieve that?
>
>
>
> getDefinitionByName() would just give be the class, but I need the declared
> instance.
>
>
>
>
>
> Warm regards,
>
> Deepak
>



-- 
Thanks and Regards,
JJain,

   If you have knowledge, let others light their candles in it --Margaret
Fuller:

Re: How to get a class instance using string name?

Posted by Deepak MS <me...@gmail.com>.
But 'myObject' here should be an actual object and not a string a believe?
However I did try both options, but that did not work.


On Fri, Aug 16, 2013 at 5:16 PM, Miguel Ferreira <
miguel.cd.ferreira@hotmail.com> wrote:

> see this link:
>
> http://stackoverflow.com/questions/468925/in-actionscript3-how-do-you-get-a-reference-to-an-objects-class
> Maybe this is enough for you?
> var classRef:Class = getDefinitionByName(getQualifiedClassName(myObject))
> as Class;
> I hope it helps.
> Miguel.
> > Date: Fri, 16 Aug 2013 17:09:12 +0530
> > Subject: How to get a class instance using string name?
> > From: megharajdeepak@gmail.com
> > To: users@flex.apache.org
> >
> > Hi there,
> >
> > Is there a way we can get a running instance in our application, by using
> > it’s id as a String?
> >
> >
> >
> > For ex:
> >
> > I have a mxml line which is
> >
> > <mx:LinearAxis id="vAxis1"  title="Growth%"
> > labelFunction="percentageformatAxis"  />
> >
> >
> >
> >
> >
> > There is a data xml in which these instance names (vAxis1, vAxis2 …)
> shall
> > be declared:
> >
> >
> >
> > <doc>
> >
> >
> > <row metricId="1" metricName="AUD" attribute="@AUD" checked="1"
> > chartType="1" verticalAxis="vAxis1">
> >
> >
> > <row metricId="2" metricName="AUD Growth %" attribute="@AUDGrowth"
> > checked="1" chartType="2" verticalAxis="vAxis2"/>
> >
> >
> > </row>
> >
> >
> > <row metricId="3" metricName="AUD MS" attribute="@AUDMSPerc" checked="0"
> > chartType="2" verticalAxis="vAxis3">
> >
> >
> >                 <row metricId="4" metricName="AUD MS Growth %"
> > attribute="@AUDMSGrowth" checked="0" chartType="1"
> verticalAxis="vAxis4"/>
> >
> >
> > </row>
> >
> >                                                                 </doc>
> >
> >
> >
> > This data would be dynamic and I am trying to assign verticalAxis
> attribute
> > value to verticalAxis property of a column series at runtime:
> >
> >
> >
> > colSeries = *new* ColumnSeries();
> >
> >                                                 colSeries.yField =
> > String(metric.@attribute);
> >
> >                                                 colSeries.displayName =
> > String(metric.@metricName);
> >
> >
> >
> >
> >
> >                                                 colSeries.verticalAxis =
> > metric.@verticalAxis; //metric.@verticalAxis here would be a string.
> But I
> > have to reference the LinearAxis that I have declared on top, which is
> > vAxis1.
> >
> >
> >             seriesArray.push(colSeries);
> >
> >
> >
> > Is there any way we can achieve that?
> >
> >
> >
> > getDefinitionByName() would just give be the class, but I need the
> declared
> > instance.
> >
> >
> >
> >
> >
> > Warm regards,
> >
> > Deepak
>
>

RE: How to get a class instance using string name?

Posted by Miguel Ferreira <mi...@hotmail.com>.
see this link:
http://stackoverflow.com/questions/468925/in-actionscript3-how-do-you-get-a-reference-to-an-objects-class
Maybe this is enough for you?
var classRef:Class = getDefinitionByName(getQualifiedClassName(myObject)) as Class;
I hope it helps.
Miguel.
> Date: Fri, 16 Aug 2013 17:09:12 +0530
> Subject: How to get a class instance using string name?
> From: megharajdeepak@gmail.com
> To: users@flex.apache.org
> 
> Hi there,
> 
> Is there a way we can get a running instance in our application, by using
> it’s id as a String?
> 
> 
> 
> For ex:
> 
> I have a mxml line which is
> 
> <mx:LinearAxis id="vAxis1"  title="Growth%"
> labelFunction="percentageformatAxis"  />
> 
> 
> 
> 
> 
> There is a data xml in which these instance names (vAxis1, vAxis2 …) shall
> be declared:
> 
> 
> 
> <doc>
> 
> 
> <row metricId="1" metricName="AUD" attribute="@AUD" checked="1"
> chartType="1" verticalAxis="vAxis1">
> 
> 
> <row metricId="2" metricName="AUD Growth %" attribute="@AUDGrowth"
> checked="1" chartType="2" verticalAxis="vAxis2"/>
> 
> 
> </row>
> 
> 
> <row metricId="3" metricName="AUD MS" attribute="@AUDMSPerc" checked="0"
> chartType="2" verticalAxis="vAxis3">
> 
> 
>                 <row metricId="4" metricName="AUD MS Growth %"
> attribute="@AUDMSGrowth" checked="0" chartType="1" verticalAxis="vAxis4"/>
> 
> 
> </row>
> 
>                                                                 </doc>
> 
> 
> 
> This data would be dynamic and I am trying to assign verticalAxis attribute
> value to verticalAxis property of a column series at runtime:
> 
> 
> 
> colSeries = *new* ColumnSeries();
> 
>                                                 colSeries.yField =
> String(metric.@attribute);
> 
>                                                 colSeries.displayName =
> String(metric.@metricName);
> 
> 
> 
> 
> 
>                                                 colSeries.verticalAxis =
> metric.@verticalAxis; //metric.@verticalAxis here would be a string. But I
> have to reference the LinearAxis that I have declared on top, which is
> vAxis1.
> 
> 
>             seriesArray.push(colSeries);
> 
> 
> 
> Is there any way we can achieve that?
> 
> 
> 
> getDefinitionByName() would just give be the class, but I need the declared
> instance.
> 
> 
> 
> 
> 
> Warm regards,
> 
> Deepak
 		 	   		  

Re: How to get a class instance using string name?

Posted by Marcus Wilkinson <wi...@gmail.com>.
There's no getElementByName, so maybe on the parent you could do
(immediately contradicting my previous comment :)
var myElement:* = parent["childId"]


On 16 August 2013 12:50, Marcus Wilkinson <wi...@gmail.com> wrote:

> I guess there's no reliable way to get the instance at runtime by id?
> Perhaps getChildByName could help?
>
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#getChildByName()
>
>
> On 16 August 2013 12:39, Deepak MS <me...@gmail.com> wrote:
>
>> Hi there,
>>
>> Is there a way we can get a running instance in our application, by using
>> it’s id as a String?
>>
>>
>>
>> For ex:
>>
>> I have a mxml line which is
>>
>> <mx:LinearAxis id="vAxis1"  title="Growth%"
>> labelFunction="percentageformatAxis"  />
>>
>>
>>
>>
>>
>> There is a data xml in which these instance names (vAxis1, vAxis2 …) shall
>> be declared:
>>
>>
>>
>> <doc>
>>
>>
>> <row metricId="1" metricName="AUD" attribute="@AUD" checked="1"
>> chartType="1" verticalAxis="vAxis1">
>>
>>
>> <row metricId="2" metricName="AUD Growth %" attribute="@AUDGrowth"
>> checked="1" chartType="2" verticalAxis="vAxis2"/>
>>
>>
>> </row>
>>
>>
>> <row metricId="3" metricName="AUD MS" attribute="@AUDMSPerc" checked="0"
>> chartType="2" verticalAxis="vAxis3">
>>
>>
>>                 <row metricId="4" metricName="AUD MS Growth %"
>> attribute="@AUDMSGrowth" checked="0" chartType="1" verticalAxis="vAxis4"/>
>>
>>
>> </row>
>>
>>                                                                 </doc>
>>
>>
>>
>> This data would be dynamic and I am trying to assign verticalAxis
>> attribute
>> value to verticalAxis property of a column series at runtime:
>>
>>
>>
>> colSeries = *new* ColumnSeries();
>>
>>                                                 colSeries.yField =
>> String(metric.@attribute);
>>
>>                                                 colSeries.displayName =
>> String(metric.@metricName);
>>
>>
>>
>>
>>
>>                                                 colSeries.verticalAxis =
>> metric.@verticalAxis; //metric.@verticalAxis here would be a string. But
>> I
>> have to reference the LinearAxis that I have declared on top, which is
>> vAxis1.
>>
>>
>>             seriesArray.push(colSeries);
>>
>>
>>
>> Is there any way we can achieve that?
>>
>>
>>
>> getDefinitionByName() would just give be the class, but I need the
>> declared
>> instance.
>>
>>
>>
>>
>>
>> Warm regards,
>>
>> Deepak
>>
>
>

Re: How to get a class instance using string name?

Posted by Marcus Wilkinson <wi...@gmail.com>.
I guess there's no reliable way to get the instance at runtime by id?
Perhaps getChildByName could help?
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#getChildByName()


On 16 August 2013 12:39, Deepak MS <me...@gmail.com> wrote:

> Hi there,
>
> Is there a way we can get a running instance in our application, by using
> it’s id as a String?
>
>
>
> For ex:
>
> I have a mxml line which is
>
> <mx:LinearAxis id="vAxis1"  title="Growth%"
> labelFunction="percentageformatAxis"  />
>
>
>
>
>
> There is a data xml in which these instance names (vAxis1, vAxis2 …) shall
> be declared:
>
>
>
> <doc>
>
>
> <row metricId="1" metricName="AUD" attribute="@AUD" checked="1"
> chartType="1" verticalAxis="vAxis1">
>
>
> <row metricId="2" metricName="AUD Growth %" attribute="@AUDGrowth"
> checked="1" chartType="2" verticalAxis="vAxis2"/>
>
>
> </row>
>
>
> <row metricId="3" metricName="AUD MS" attribute="@AUDMSPerc" checked="0"
> chartType="2" verticalAxis="vAxis3">
>
>
>                 <row metricId="4" metricName="AUD MS Growth %"
> attribute="@AUDMSGrowth" checked="0" chartType="1" verticalAxis="vAxis4"/>
>
>
> </row>
>
>                                                                 </doc>
>
>
>
> This data would be dynamic and I am trying to assign verticalAxis attribute
> value to verticalAxis property of a column series at runtime:
>
>
>
> colSeries = *new* ColumnSeries();
>
>                                                 colSeries.yField =
> String(metric.@attribute);
>
>                                                 colSeries.displayName =
> String(metric.@metricName);
>
>
>
>
>
>                                                 colSeries.verticalAxis =
> metric.@verticalAxis; //metric.@verticalAxis here would be a string. But I
> have to reference the LinearAxis that I have declared on top, which is
> vAxis1.
>
>
>             seriesArray.push(colSeries);
>
>
>
> Is there any way we can achieve that?
>
>
>
> getDefinitionByName() would just give be the class, but I need the declared
> instance.
>
>
>
>
>
> Warm regards,
>
> Deepak
>