Flash Builder 4.6, Mobile, Dynamic load image into custom ItemRender - actionscript-3

Where is good place to load image in custom itemrender for list. I try to do it in createChildren where i create my holder for image, but data is not set yet.. I think in data function is not ok, because is calinig every time when user scroll.

You need to set the data/url to the image in commitProperties.

You didn't tell us what the image is and how it relates to your itemRenderer. Here are a few options:
If your image will not change based on the data then create your image class in createChildren(). Set the property on it in the createChildren() method; if it is static. If it is something that may change you may consider setting it in commitProperties().
If your image will change based on the data; then you should change it either in the set data method or in a dataChange event handler. I prefer the latter, but that is just preference. An itemRenderer is re-used as the list is scrolled. So the data that your renderer represents changes with it; and so should your visual display.
If lots of the elements of your dataProvider may use the same image; you can write conditional logic to determine whether or not the image should be loaded again. This would prevent the image from reloading again unnecessarily.

Related

Is it possible to customize how image is loaded while still using `img.loading` attribute?

For images in my webpage, instead of just specifying some image url, I need to load the image data from my own API as a binary data, and then set the src as data/jpeg;base64,..... i.e, I probably need a customized function to load the image content.
However I also want to do the loading lazily. So the ways I can think of are:
set src as empty initially, and listen to various mouse events myself or use Intersection Observer API to trigger my customized function to actually load and set src
find some way to override image's loading function? so that I could still use the native lazy loading provided by chrome?
Is option 2 possible? If so, how to override?
Thanks!

TileMap not generated; add to stage?

I'm failrly new to LibGDX and I'm running into a problem.
I'm building a classically styled RPG/Adventure game in which I'm using a TiledMap(-Renderer) to create the map. I've followed different tutorials but can't get it to work. (last one was DPG's: Full working example link)
What I need, is a column of buttons on the right side of the screen (implemented that through ImageButtons). One of these buttons lead to a settings-kind of screen and another one should lead to the game map. Under a ClickListener of the button I've added DPK's code of
MapHelper map = new MapHelper();
map.setPackerDirectory("data/packer");
map.loadMap("data/world/level1/level.tmx");
map.prepareCamera((int)stage.getWidth(), (int)stage.getHeight());
map.getCamera().update();
map.render();
The MapHelper class is an exact copy of dpk's, only change above is the setting of the width and height of the camera. Any suggestion what I'm doing wrong here?
I don't think you want to invoke map.render() in the ClickListener callback. That would mean the map is only rendered when you click, and then not re-rendered (generally everything gets re-rendered on every screen re-fresh).
I think you need to track the map in your application class, and in the ClickListener callback you need to set a flag or somehow "enable" the map (perhaps setting it to something other than null). Then in the application's render() method you can check to see if the map should be rendered or not, and render it if so.
Specifically, move the calls to prepareCamera, getCamera and render out of the ClickListener.

Getting a list of the rendered items

I have my own custom component. This component extends from a basic container. I want to be able to access the itemRenderer instances that are being visualized. I know that the component mx:list has an internal getter that provides an array of Arrays containing the itemRenderer instances that render each data provider item. I want the same thing. Any idea how of how to do that?
To be more specific: I am setting the selected property of my dataProvider items to true or false. From the updateDisplayList funcion of my ItemRenderer I check for changes of the property and correct the border color of the selected ones. Unfortunately I have to force the updateDisplayList function. I already did this once on a ItemRenderer from a list. Only with the list it was practical because by making my own list I was able to get the list of items being rendered and therefore visualized (cannot be many). It was no overhead to go trough the rendered Items and updateDisplayList. But in this case I can have 100 items. Imagine checking and changing styles on so many items. Thanks
The Flex architects intentionally made this difficult to do, because they are properly encapsulating the component. In short, to even try to do this is a violation of good OOP principles.
That said, about 90% of the things you are probably trying to do can be done by manipulating the data item, and the remaining 10% can be done by using a ClassFactory for your itemRenderer that sets a custom property on your itemRenderer to a callback where you can look at the data available to the containing context and provide back a value based on that.
If you elaborate a bit more on your end goal, I can give you more specifics.
Edit in light of clarification:
You need to make your data object class dispatch an event when it changes (one way is to make it bindable, or just make the selected property bindable). Then, in your renderer, listen for the change event and take the appropriate action.
A second way to handle this would just be to refresh() the collection, storing the selectedItem first (if you care about that) and resetting it once the refresh has finished.
I believe you can access the itemRenderer instances through getChildAt method. Flex 3's container overrides "getChildAt", "numChildren", given that some children are logical children, while some are decorative children such as background, border and scrollbars.
Keep in mind that itemRenderer may not right away become available upon dataProvider assignment, as they may be created during the next component lifecycle. Check with the underlying container's documentation and find out which event to be listened when the renderers are surely created, so you can reliably access them.

flex broken spark image

On my air application, I try to load image like this:
var imAc:Image=new Image();
imAc.source=rootFile+value+"-V-"+label+".png";
Sometimes, image source doesn't exist.
In this case, broken icon appear but if this error appear I'd like to change image source
imAc.source= null
With mx:Image ioError property exist but I don't find the same with spark image.
Do you know how to do that?
Thanks
If you're using a spark image control, the ioError event can be used to trap the error and null out the value (or put up a placeholder image). If you need more granularity than that, or if you're in flex 3, you can use a Loader.
I'm not aware of any methods within the Spark Image component that allow you to check of its existence, but the File class does.
new File("your/file/path").exists
will return whether or not he file is present.
The result of this can then determine whether to set the source property to null.

What is the complementary event of 'show' for flex displayobjects

Since flex memory management is poor, objects once instantiated dont die very easily (even when they go out of scope), one would need to check on various properties of components. I am using one such thing to know if the screen (which is a display object) is in current view. For this I am turning on a boolean property (currently visible), and I am setting it true on show event of the display object.
What I need to know is, which event (something opposite of show, e.g left?) could be used when the screen is replaced by another display object?
Something like focusIn and focusOut from dotnet.
Or if there is some property which could directly tell me if the display object is currently in view (hasFocus doesnt seem to be giving me expected results).
Thanks.
You can Use PropertyChageEvent check the documentation and base of the newValue and kind property you can do some action :
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/events/PropertyChangeEvent.html
hope this help
Name of the event is: removedFromStage.