header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Arthur Rocha
Points:0
Posts:0

5/20/2010 10:18:50 AM

Title: Same instance of the Image in several Containers


Good afternoon,
I'll copy the forum discussion because it may help in solving my problems, I thank everyone's help.
___________________________________________

Arthur:

Guys, in my application I have an itemRenderer to a Tree, which
uses two images and one label. Only it is taking around
10 sec. to render my list that has only 20 items.
I thought a solution would be, if possible, use only one
instance of an Image for all items in this list (singleton).
To test this I did the following test:

          [Bindable]
          var imageResource:ImageResource =
                      ImageResource.getInstancia();

  public function adiciona():void
  {
      var image:Image = new Image();
      image.source = imageResource.iconeSalvar;
      box1.addChild(image);
      box2.addChild(image);
  }

  ]]>
  </mx:Script>
  <containers:MVHBox creationComplete="adiciona()">
      <mx:Box id="box1" />
      <mx:Box id="box2" />
  </containers:MVHBox>


but to add the image in "box2" disappears from the "box1". Someone
know any way to use the same instance (not a "copy")
of an object in different places of the screen?
Any other ideas for improving the performance of my itemRenderer?

Thanks,
Arthur Rocha.
___________________________________________

Vaibhav:

Here you go, follow the syntax:

[Embed(source="/assets/images/Login.png")]
public static var imgLoginBG:Class;

this will give you the image as a class.
No need to define ImageResource as singleton. Just access the image by ImageResource .imgLoginBG.
__________________________________________
Arthur:

Hi Vaibhav,
ImageResource my file is just a set of images "Embed", inside it I have mapped images exactly the way you recommended above. My point is not to replicate the image (source attribute of the mx: Image), that I do with "Embed" like you said, I would like to use only one object mx:Image in different mx:HBox. For example, using a mx:TextInput in different mx:Box :

 public function addTextInput():void
 {
  var txt:TextInput = new TextInput();
  txt.width = 100;
  box1.addChild(txt);
  box2.addChild(txt);
  box3.addChild(txt);   
 }             
    ]]>
</mx:Script>
<mx:Box id="box1" />
<mx:Box id="box2" />

<mx:Box id="box3" />
 
but when this code runs only in the picture is box3. When you add it in a mx:Container she leaves the mx:Container earlier. Does anyone know how to remain an object Display mx:Container in more than window (mx:Box) one at a time? What is changed in one of the objects will be reflected to the other because they are the same object, but in different locations of the screen. Someone already implemented this? Thanks, Arthur Rocha.



1
bob_senior
Points: 1300
Posts:0
5/20/2010 12:24:37 PM



Actionscript 3 does not allow to create duplicates.So we have to create anew instance of the class. You have to use like this to create multiple copies.

var image:Image = new Image();
image.source = imageResource.iconeSalvar;

var image1:Image = new Image();
image1.source = imageResource.iconeSalvar;

box1.addChild(image);
box2.addChild(image1);

2
Warrior
Points: 420
Posts:0
5/20/2010 12:32:57 PM



10 seconds for 20 images is too long to render, rendering is the process which depends upon performance of hardware also. Try testing it on some other machine also . 20 images can take too much time if they are of very big size like 1000 pixels. Or are loaded at runtime. Else I don't see any reason to take so much time to render.

3
Arthur Rocha
Points: 0
Posts:0
5/20/2010 1:46:02 PM



Thanks for the answers!
I really was afraid of this answer: "Actionscript 3 does not allow to create duplicates.So we have to create anew instance of the class."
For the record, I have 3 mx:Images and a mx:Label on my itemRenderer, I use a mx:Canvas then there estimations of position for the items if there are fewer than three images, and my items have subitems that can contain up to three images. With flexProfile identified that are being created 76 mx:Image. I'll redo my itemRenderer and instead of using three images I'll use just one (join the three image files in just one), so I get only one instance of mx:Image by itemRender at least.
Thanks for your help!

4
Flash_Guy
Points: 830
Posts:0
5/20/2010 9:31:42 PM



if you can share your running project, I can check where is the performance problem and any possible solution.


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 8+6 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions