[英]displaying an image in flex
I worked with Haxe and actionscript programming, but I'm new to flex. 我曾经使用过Haxe和Actionscript编程,但是我是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
. 如果我想从AS3中的服务器(闪耀的)获取图像,则将其
Loader
到Loader
加载程序,然后将其添加到例如MovieClip
。 Should I do the same to load an image in flex? 在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
? 如果我在炽烈的服务器上有一个Image,有什么更好的方法来获取它:通过Java传递(即读取它,然后传递给客户端)或直接使用
Loader
?
Thank you in advance! 先感谢您!
BlazeDS is normally used to send objects serialized in AMF. BlazeDS通常用于发送以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. 对图像执行此操作似乎有点过分,因为它将作为
ByteArray
发送,但是您将花费资源来处理它。 Possibly, a better way, especially if the image is a static content, just serve it as a static file with whatever server running BlazeDS. 可能是一种更好的方法,尤其是在图像是静态内容的情况下,只需将其用作运行BlazeDS的任何服务器的静态文件即可。
There are different ways you can use an image in Flex. 在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. Flex框架的一些特殊之处是:将其用作
Image
组件的源,但是对于许多任务来说,该组件太大了。 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. 有
BitmapImage
,它打算是Image
的轻量级副本,但它可能不具备所有所需的功能(它不继承自InteractiveObject
,因此它不能响应鼠标事件。它也只能作为Spark组件使用。
What I usually do, if I need to use images is this: 如果需要使用图像,通常要做的是:
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. 如果需要将它们缓存在程序中(以重用它们的
BitmapData
),则可以编写一个类来负责加载和缓存结果。
I write a very simple component that extends UIComponent
and uses it's graphics
property to draw the given BitmapData
into it. 我编写了一个非常简单的组件,该组件扩展了
UIComponent
并使用其graphics
属性将给定的BitmapData
绘制到其中。 This usually allows for simple sharing of the same BitmapData
in several components. 这通常允许在多个组件中简单共享同一
BitmapData
。
Have this component override updateDisplayList
method so that it would scale or trim the BitmapData
it uses. 让此组件重写
updateDisplayList
方法,以便它可以缩放或修剪其使用的BitmapData
。
I do use Loader
to load images, as there's really no other way to do it. 我确实使用
Loader
来加载图像,因为实际上没有其他方法可以这样做。 Other components such as Image
or SWFLoader
or BitmapImage
use Loader too and they don't add anything of value on top of that. 其他组件(例如
Image
或SWFLoader
或BitmapImage
使用Loader,并且它们不会在此之上添加任何有价值的东西。
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. 可能的是,如果您需要slice-9网格功能,那么Spark组件集中会内置一些功能,但是我还是宁愿自己做,也要依靠它。 Flex components aren't to be trusted really.
Flex组件并不是真正值得信赖的。
Not necessary. 不必要。 Setting the
source
property of a spark.components.Image
object will load the image. 设置
spark.components.Image
对象的source
属性将加载图像。
For loading swf files, you can use mx.controls.SWFLoader
in the same way. 要加载swf文件,可以以相同方式使用
mx.controls.SWFLoader
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.