You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by mark goldin <ma...@gmail.com> on 2015/03/18 16:18:27 UTC

Custom Item renderer to show various icons

I need to have a custom renderer in ADG to show different icons in a cell.
Here is my simplified code for the renderer:

private var _IconsSourceArrayCol:ArrayCollection = new ArrayCollection();

[Embed(source=".icon1.png")]
private var _icon1:Class;
[Embed(source="icon2.png")]
private var _icon2:Class;

....
override public function set data(value:Object):void
{
super.data = value;
if (data)
{
_IconsSourceArrayCol.addItem({source:_icon1});
                _IconsSourceArrayCol.addItem({source:_icon2});
image.source = _IconsSourceArrayCol[data.status].source;
}
}

Is there a better way of doing it?

Thanks

Re: Custom Item renderer to show various icons

Posted by Alex Harui <ah...@adobe.com>.
An image source can be a class or embed or bitmap instance.

It is important to decide if want to work with embedded images or not.
The TreeItemRenderer works with embedded images and uses different icons.

On 3/21/15, 5:40 AM, "mark goldin" <ma...@gmail.com> wrote:

>How would this work if I compile all my resources into a swf file? How can
>I then get an image source at the run-time?
>
>Thanks
>
>On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui <ah...@adobe.com> wrote:
>
>> Did you try:
>>
>> if (data)
>> {
>>   var c:Class = data.status == 0 ? _icon1 : _icon2;
>>   image.source = new c();
>> }
>>
>>
>>
>>
>> On 3/18/15, 8:18 AM, "mark goldin" <ma...@gmail.com> wrote:
>>
>> >I need to have a custom renderer in ADG to show different icons in a
>>cell.
>> >Here is my simplified code for the renderer:
>> >
>> >private var _IconsSourceArrayCol:ArrayCollection = new
>>ArrayCollection();
>> >
>> >[Embed(source=".icon1.png")]
>> >private var _icon1:Class;
>> >[Embed(source="icon2.png")]
>> >private var _icon2:Class;
>> >
>> >....
>> >override public function set data(value:Object):void
>> >{
>> >super.data = value;
>> >if (data)
>> >{
>> >_IconsSourceArrayCol.addItem({source:_icon1});
>> >                _IconsSourceArrayCol.addItem({source:_icon2});
>> >image.source = _IconsSourceArrayCol[data.status].source;
>> >}
>> >}
>> >
>> >Is there a better way of doing it?
>> >
>> >Thanks
>>
>>


Re: Custom Item renderer to show various icons

Posted by Subs <su...@leeburrows.com>.
sorry; i misunderstood your issue

On 21/03/2015 17:51, mark goldin wrote:
> I am not. I am trying to find a solution for loading images using their
> names received from backend.
>
> On Sat, Mar 21, 2015 at 12:18 PM, Subs <su...@leeburrows.com> wrote:
>
>> how are you creating your swf file?
>>
>>
>> On 21/03/2015 17:12, mark goldin wrote:
>>
>>> But what I dont understand is how I will provide a path to an image in a
>>> first place.
>>>
>>>
>>>
>>> On Sat, Mar 21, 2015 at 11:27 AM, Subs <su...@leeburrows.com>
>>> wrote:
>>>
>>>   you can access library objects of the swf with embed:
>>>> [Embed(source='SWFFileName.swf', symbol='symbolName')]
>>>>
>>>> (see http://help.adobe.com/en_US/flex/using/
>>>> WS2db454920e96a9e51e63e3d11c0b
>>>> f60546-7ff2.html#WS2db454920e96a9e51e63e3d11c0bf69084-7fa3)
>>>>
>>>>
>>>>
>>>> On 21/03/2015 16:00, Chris Martin wrote:
>>>>
>>>>   How would this work if I compile all my resources into a swf file? How
>>>>>> can
>>>>>>>> I then get an image source at the run-time?
>>>>>>>>> Thanks
>>>>>>>>>
>>>>>>>>> On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui<ah...@adobe.com>
>>>>>>>>>
>>>>>>>> wrote:
>>>>>>> Did you try:
>>>>>>>>>>> if (data)
>>>>>>>>>>> {
>>>>>>>>>>>     var c:Class = data.status == 0 ? _icon1 : _icon2;
>>>>>>>>>>>     image.source = new c();
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>> --
>>>> Lee Burrows
>>>> ActionScripter
>>>>
>>>>
>>>>
>> --
>> Lee Burrows
>> ActionScripter
>>
>>

-- 
Lee Burrows
ActionScripter


Re: Custom Item renderer to show various icons

Posted by mark goldin <ma...@gmail.com>.
I am not. I am trying to find a solution for loading images using their
names received from backend.

On Sat, Mar 21, 2015 at 12:18 PM, Subs <su...@leeburrows.com> wrote:

> how are you creating your swf file?
>
>
> On 21/03/2015 17:12, mark goldin wrote:
>
>> But what I dont understand is how I will provide a path to an image in a
>> first place.
>>
>>
>>
>> On Sat, Mar 21, 2015 at 11:27 AM, Subs <su...@leeburrows.com>
>> wrote:
>>
>>  you can access library objects of the swf with embed:
>>>
>>> [Embed(source='SWFFileName.swf', symbol='symbolName')]
>>>
>>> (see http://help.adobe.com/en_US/flex/using/
>>> WS2db454920e96a9e51e63e3d11c0b
>>> f60546-7ff2.html#WS2db454920e96a9e51e63e3d11c0bf69084-7fa3)
>>>
>>>
>>>
>>> On 21/03/2015 16:00, Chris Martin wrote:
>>>
>>>  How would this work if I compile all my resources into a swf file? How
>>>>
>>>>> can
>>>>>>
>>>>>>> I then get an image source at the run-time?
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>>
>>>>>>>> On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui<ah...@adobe.com>
>>>>>>>>
>>>>>>> wrote:
>>>>>
>>>>>> Did you try:
>>>>>>>>>>
>>>>>>>>>> if (data)
>>>>>>>>>> {
>>>>>>>>>>    var c:Class = data.status == 0 ? _icon1 : _icon2;
>>>>>>>>>>    image.source = new c();
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>> --
>>> Lee Burrows
>>> ActionScripter
>>>
>>>
>>>
> --
> Lee Burrows
> ActionScripter
>
>

Re: Custom Item renderer to show various icons

Posted by Subs <su...@leeburrows.com>.
how are you creating your swf file?

On 21/03/2015 17:12, mark goldin wrote:
> But what I dont understand is how I will provide a path to an image in a
> first place.
>
>
>
> On Sat, Mar 21, 2015 at 11:27 AM, Subs <su...@leeburrows.com> wrote:
>
>> you can access library objects of the swf with embed:
>>
>> [Embed(source='SWFFileName.swf', symbol='symbolName')]
>>
>> (see http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0b
>> f60546-7ff2.html#WS2db454920e96a9e51e63e3d11c0bf69084-7fa3)
>>
>>
>>
>> On 21/03/2015 16:00, Chris Martin wrote:
>>
>>> How would this work if I compile all my resources into a swf file? How
>>>>> can
>>>>>>> I then get an image source at the run-time?
>>>>>>>
>>>>>>> Thanks
>>>>>>>
>>>>>>> On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui<ah...@adobe.com>
>>>> wrote:
>>>>>>>>> Did you try:
>>>>>>>>>
>>>>>>>>> if (data)
>>>>>>>>> {
>>>>>>>>>    var c:Class = data.status == 0 ? _icon1 : _icon2;
>>>>>>>>>    image.source = new c();
>>>>>>>>> }
>> --
>> Lee Burrows
>> ActionScripter
>>
>>

-- 
Lee Burrows
ActionScripter


Re: Custom Item renderer to show various icons

Posted by mark goldin <ma...@gmail.com>.
But what I dont understand is how I will provide a path to an image in a
first place.



On Sat, Mar 21, 2015 at 11:27 AM, Subs <su...@leeburrows.com> wrote:

> you can access library objects of the swf with embed:
>
> [Embed(source='SWFFileName.swf', symbol='symbolName')]
>
> (see http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0b
> f60546-7ff2.html#WS2db454920e96a9e51e63e3d11c0bf69084-7fa3)
>
>
>
> On 21/03/2015 16:00, Chris Martin wrote:
>
>> How would this work if I compile all my resources into a swf file? How
>>>
>> > >can
>>
>>> > > >I then get an image source at the run-time?
>>> > > >
>>> > > >Thanks
>>> > > >
>>> > > >On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui<ah...@adobe.com>
>>> wrote:
>>> > > >
>>>
>>>> > > > >Did you try:
>>>> > > > >
>>>> > > > >if (data)
>>>> > > > >{
>>>> > > > >   var c:Class = data.status == 0 ? _icon1 : _icon2;
>>>> > > > >   image.source = new c();
>>>> > > > >}
>>>>
>>>
> --
> Lee Burrows
> ActionScripter
>
>

Re: Custom Item renderer to show various icons

Posted by Subs <su...@leeburrows.com>.
you can access library objects of the swf with embed:

[Embed(source='SWFFileName.swf', symbol='symbolName')]

(see 
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf60546-7ff2.html#WS2db454920e96a9e51e63e3d11c0bf69084-7fa3)


On 21/03/2015 16:00, Chris Martin wrote:
>> How would this work if I compile all my resources into a swf file? How
> > >can
>> > > >I then get an image source at the run-time?
>> > > >
>> > > >Thanks
>> > > >
>> > > >On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui<ah...@adobe.com>  wrote:
>> > > >
>>> > > > >Did you try:
>>> > > > >
>>> > > > >if (data)
>>> > > > >{
>>> > > > >   var c:Class = data.status == 0 ? _icon1 : _icon2;
>>> > > > >   image.source = new c();
>>> > > > >}

-- 
Lee Burrows
ActionScripter


RE: Custom Item renderer to show various icons

Posted by Chris Martin <ch...@outlook.com>.
Hmm, I might be misunderstanding what you're looking for.   I think you're asking how to get the source of the image at run time. Source being the image content itself. As an example if you were to use the ResourceManager, you can get the source of the image at runtime by doing the following.
 
_icon1 = this.resourceManager.getClass("imageBundle","iconForState0");
_icon2 = this.resourceManager.getClass("imageBundle","iconForState1");
 
This can be more dynamic than using the Embed metatag, as you can use a variable to supply the "resourceName" parameter of getClass and pull in any of the images in the resource bundle dynamically at runtime.
 
Chris
 
> Date: Sat, 21 Mar 2015 10:11:49 -0500
> Subject: Re: Custom Item renderer to show various icons
> From: markzolotoy@gmail.com
> To: users@flex.apache.org
> 
> Still, both solutions expect images to be embed at a compile time meaning
> hard coding their names. I am trying to avoid that.
> 
> Thanks
> 
> On Sat, Mar 21, 2015 at 9:55 AM, Chris Martin <ch...@outlook.com> wrote:
> 
> > You can embed your image assets through the Embed metatag [1].  Or you can
> > get a little fancy and use the ResourceManager to manage all of your
> > embedded image assets [2].
> >
> > Chris
> >
> > [1]
> > http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf60546-7ff2.html
> > [2]
> > http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f3a.html
> >
> > > Date: Sat, 21 Mar 2015 07:40:16 -0500
> > > Subject: Re: Custom Item renderer to show various icons
> > > From: markzolotoy@gmail.com
> > > To: users@flex.apache.org
> > >
> > > How would this work if I compile all my resources into a swf file? How
> > can
> > > I then get an image source at the run-time?
> > >
> > > Thanks
> > >
> > > On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui <ah...@adobe.com> wrote:
> > >
> > > > Did you try:
> > > >
> > > > if (data)
> > > > {
> > > >   var c:Class = data.status == 0 ? _icon1 : _icon2;
> > > >   image.source = new c();
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > > On 3/18/15, 8:18 AM, "mark goldin" <ma...@gmail.com> wrote:
> > > >
> > > > >I need to have a custom renderer in ADG to show different icons in a
> > cell.
> > > > >Here is my simplified code for the renderer:
> > > > >
> > > > >private var _IconsSourceArrayCol:ArrayCollection = new
> > ArrayCollection();
> > > > >
> > > > >[Embed(source=".icon1.png")]
> > > > >private var _icon1:Class;
> > > > >[Embed(source="icon2.png")]
> > > > >private var _icon2:Class;
> > > > >
> > > > >....
> > > > >override public function set data(value:Object):void
> > > > >{
> > > > >super.data = value;
> > > > >if (data)
> > > > >{
> > > > >_IconsSourceArrayCol.addItem({source:_icon1});
> > > > >                _IconsSourceArrayCol.addItem({source:_icon2});
> > > > >image.source = _IconsSourceArrayCol[data.status].source;
> > > > >}
> > > > >}
> > > > >
> > > > >Is there a better way of doing it?
> > > > >
> > > > >Thanks
> > > >
> > > >
> >
> >
 		 	   		  

Re: Custom Item renderer to show various icons

Posted by Julio Carneiro <ju...@4ctv.com>.
can't you simply set 'source' to the image URL?

if you want images to load at runtime, all you need to do is set image.source to the external image's URL.
Flex will load the image for you, and disposed of it when not needed anymore.

hth
julio

On Mar 21, 2015, at 12:11 PM, mark goldin <ma...@gmail.com> wrote:

> Still, both solutions expect images to be embed at a compile time meaning
> hard coding their names. I am trying to avoid that.
> 
> Thanks
> 
> On Sat, Mar 21, 2015 at 9:55 AM, Chris Martin <ch...@outlook.com> wrote:
> 
>> You can embed your image assets through the Embed metatag [1].  Or you can
>> get a little fancy and use the ResourceManager to manage all of your
>> embedded image assets [2].
>> 
>> Chris
>> 
>> [1]
>> http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf60546-7ff2.html
>> [2]
>> http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f3a.html
>> 
>>> Date: Sat, 21 Mar 2015 07:40:16 -0500
>>> Subject: Re: Custom Item renderer to show various icons
>>> From: markzolotoy@gmail.com
>>> To: users@flex.apache.org
>>> 
>>> How would this work if I compile all my resources into a swf file? How
>> can
>>> I then get an image source at the run-time?
>>> 
>>> Thanks
>>> 
>>> On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui <ah...@adobe.com> wrote:
>>> 
>>>> Did you try:
>>>> 
>>>> if (data)
>>>> {
>>>>  var c:Class = data.status == 0 ? _icon1 : _icon2;
>>>>  image.source = new c();
>>>> }
>>>> 
>>>> 
>>>> 
>>>> 
>>>> On 3/18/15, 8:18 AM, "mark goldin" <ma...@gmail.com> wrote:
>>>> 
>>>>> I need to have a custom renderer in ADG to show different icons in a
>> cell.
>>>>> Here is my simplified code for the renderer:
>>>>> 
>>>>> private var _IconsSourceArrayCol:ArrayCollection = new
>> ArrayCollection();
>>>>> 
>>>>> [Embed(source=".icon1.png")]
>>>>> private var _icon1:Class;
>>>>> [Embed(source="icon2.png")]
>>>>> private var _icon2:Class;
>>>>> 
>>>>> ....
>>>>> override public function set data(value:Object):void
>>>>> {
>>>>> super.data = value;
>>>>> if (data)
>>>>> {
>>>>> _IconsSourceArrayCol.addItem({source:_icon1});
>>>>>               _IconsSourceArrayCol.addItem({source:_icon2});
>>>>> image.source = _IconsSourceArrayCol[data.status].source;
>>>>> }
>>>>> }
>>>>> 
>>>>> Is there a better way of doing it?
>>>>> 
>>>>> Thanks
>>>> 
>>>> 
>> 
>> 

--
Julio Carneiro




Re: Custom Item renderer to show various icons

Posted by mark goldin <ma...@gmail.com>.
Still, both solutions expect images to be embed at a compile time meaning
hard coding their names. I am trying to avoid that.

Thanks

On Sat, Mar 21, 2015 at 9:55 AM, Chris Martin <ch...@outlook.com> wrote:

> You can embed your image assets through the Embed metatag [1].  Or you can
> get a little fancy and use the ResourceManager to manage all of your
> embedded image assets [2].
>
> Chris
>
> [1]
> http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf60546-7ff2.html
> [2]
> http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f3a.html
>
> > Date: Sat, 21 Mar 2015 07:40:16 -0500
> > Subject: Re: Custom Item renderer to show various icons
> > From: markzolotoy@gmail.com
> > To: users@flex.apache.org
> >
> > How would this work if I compile all my resources into a swf file? How
> can
> > I then get an image source at the run-time?
> >
> > Thanks
> >
> > On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui <ah...@adobe.com> wrote:
> >
> > > Did you try:
> > >
> > > if (data)
> > > {
> > >   var c:Class = data.status == 0 ? _icon1 : _icon2;
> > >   image.source = new c();
> > > }
> > >
> > >
> > >
> > >
> > > On 3/18/15, 8:18 AM, "mark goldin" <ma...@gmail.com> wrote:
> > >
> > > >I need to have a custom renderer in ADG to show different icons in a
> cell.
> > > >Here is my simplified code for the renderer:
> > > >
> > > >private var _IconsSourceArrayCol:ArrayCollection = new
> ArrayCollection();
> > > >
> > > >[Embed(source=".icon1.png")]
> > > >private var _icon1:Class;
> > > >[Embed(source="icon2.png")]
> > > >private var _icon2:Class;
> > > >
> > > >....
> > > >override public function set data(value:Object):void
> > > >{
> > > >super.data = value;
> > > >if (data)
> > > >{
> > > >_IconsSourceArrayCol.addItem({source:_icon1});
> > > >                _IconsSourceArrayCol.addItem({source:_icon2});
> > > >image.source = _IconsSourceArrayCol[data.status].source;
> > > >}
> > > >}
> > > >
> > > >Is there a better way of doing it?
> > > >
> > > >Thanks
> > >
> > >
>
>

RE: Custom Item renderer to show various icons

Posted by Chris Martin <ch...@outlook.com>.
You can embed your image assets through the Embed metatag [1].  Or you can get a little fancy and use the ResourceManager to manage all of your embedded image assets [2].
 
Chris
 
[1] http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf60546-7ff2.html
[2] http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f3a.html
 
> Date: Sat, 21 Mar 2015 07:40:16 -0500
> Subject: Re: Custom Item renderer to show various icons
> From: markzolotoy@gmail.com
> To: users@flex.apache.org
> 
> How would this work if I compile all my resources into a swf file? How can
> I then get an image source at the run-time?
> 
> Thanks
> 
> On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui <ah...@adobe.com> wrote:
> 
> > Did you try:
> >
> > if (data)
> > {
> >   var c:Class = data.status == 0 ? _icon1 : _icon2;
> >   image.source = new c();
> > }
> >
> >
> >
> >
> > On 3/18/15, 8:18 AM, "mark goldin" <ma...@gmail.com> wrote:
> >
> > >I need to have a custom renderer in ADG to show different icons in a cell.
> > >Here is my simplified code for the renderer:
> > >
> > >private var _IconsSourceArrayCol:ArrayCollection = new ArrayCollection();
> > >
> > >[Embed(source=".icon1.png")]
> > >private var _icon1:Class;
> > >[Embed(source="icon2.png")]
> > >private var _icon2:Class;
> > >
> > >....
> > >override public function set data(value:Object):void
> > >{
> > >super.data = value;
> > >if (data)
> > >{
> > >_IconsSourceArrayCol.addItem({source:_icon1});
> > >                _IconsSourceArrayCol.addItem({source:_icon2});
> > >image.source = _IconsSourceArrayCol[data.status].source;
> > >}
> > >}
> > >
> > >Is there a better way of doing it?
> > >
> > >Thanks
> >
> >
 		 	   		  

Re: Custom Item renderer to show various icons

Posted by mark goldin <ma...@gmail.com>.
How would this work if I compile all my resources into a swf file? How can
I then get an image source at the run-time?

Thanks

On Wed, Mar 18, 2015 at 3:42 PM, Alex Harui <ah...@adobe.com> wrote:

> Did you try:
>
> if (data)
> {
>   var c:Class = data.status == 0 ? _icon1 : _icon2;
>   image.source = new c();
> }
>
>
>
>
> On 3/18/15, 8:18 AM, "mark goldin" <ma...@gmail.com> wrote:
>
> >I need to have a custom renderer in ADG to show different icons in a cell.
> >Here is my simplified code for the renderer:
> >
> >private var _IconsSourceArrayCol:ArrayCollection = new ArrayCollection();
> >
> >[Embed(source=".icon1.png")]
> >private var _icon1:Class;
> >[Embed(source="icon2.png")]
> >private var _icon2:Class;
> >
> >....
> >override public function set data(value:Object):void
> >{
> >super.data = value;
> >if (data)
> >{
> >_IconsSourceArrayCol.addItem({source:_icon1});
> >                _IconsSourceArrayCol.addItem({source:_icon2});
> >image.source = _IconsSourceArrayCol[data.status].source;
> >}
> >}
> >
> >Is there a better way of doing it?
> >
> >Thanks
>
>

Re: Custom Item renderer to show various icons

Posted by Alex Harui <ah...@adobe.com>.
Did you try:

if (data)
{
  var c:Class = data.status == 0 ? _icon1 : _icon2;
  image.source = new c();
}




On 3/18/15, 8:18 AM, "mark goldin" <ma...@gmail.com> wrote:

>I need to have a custom renderer in ADG to show different icons in a cell.
>Here is my simplified code for the renderer:
>
>private var _IconsSourceArrayCol:ArrayCollection = new ArrayCollection();
>
>[Embed(source=".icon1.png")]
>private var _icon1:Class;
>[Embed(source="icon2.png")]
>private var _icon2:Class;
>
>....
>override public function set data(value:Object):void
>{
>super.data = value;
>if (data)
>{
>_IconsSourceArrayCol.addItem({source:_icon1});
>                _IconsSourceArrayCol.addItem({source:_icon2});
>image.source = _IconsSourceArrayCol[data.status].source;
>}
>}
>
>Is there a better way of doing it?
>
>Thanks