简体   繁体   中英

displaying an image in flex

I worked with Haxe and actionscript programming, but I'm new to flex. Here's my question. If I want to get image from server (blazeds) in AS3 I'll load it to Loader a loader and then add it to some eg MovieClip . Should I do the same to load an image in flex? Or there some common for flex schema for doing that?

Another question is. If I have an Image on blazeds server what will a better way to get it: to pass it through java (ie read it, and then pass to client) or directcly with Loader ?

Thank you in advance!

BlazeDS is normally used to send objects serialized in AMF. It looks like an overkill to do this for an image, as it will be sent as ByteArray , but you'll spend resources processing it. Possibly, a better way, especially if the image is a static content, just serve it as a static file with whatever server running BlazeDS.

There are different ways you can use an image in Flex. Some particular to Flex framework are: use it as a source to the Image component, however, this component is somewhat too big for a number of tasks. For example, creating tiles of the same image will be very ineffective if you use this component. There is BitmapImage , which is meant to be a lightweight counterpart of Image , but it may not have all the desired functionality (it doesn't inherit from InteractiveObject , so it cannot respond to mouse events. It is also only available as Spark component.

What I usually do, if I need to use images is this:

  1. If I need to cache them in the program (to reuse their BitmapData ) I write a class that is responsible for loading and caching the results.

  2. I write a very simple component that extends UIComponent and uses it's graphics property to draw the given BitmapData into it. This usually allows for simple sharing of the same BitmapData in several components.

  3. Have this component override updateDisplayList method so that it would scale or trim the BitmapData it uses.

I do use Loader to load images, as there's really no other way to do it. Other components such as Image or SWFLoader or BitmapImage use Loader too and they don't add anything of value on top of that.

Possibly, if you need slice-9-grid functionality, then there is something built-in in the Spark set of components, yet I'd still rather do it myself then rely on it. Flex components aren't to be trusted really.

Not necessary. Setting the source property of a spark.components.Image object will load the image.

For loading swf files, you can use mx.controls.SWFLoader in the same way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM