简体   繁体   English

从actionscript3访问flex中的图像组件

[英]accessing an image component in flex from actionscript3

I have an image component in flex (mxml file), like below 我在flex(mxml文件)中有一个图像组件,如下所示

<mx:image id="imageID"/>

I have a separate actionscript class and I am trying to set the source of the image from the init() in the actionscript class. 我有一个单独的actionscript类,并且尝试从actionscript类的init()设置图像源。

I am trying to access it like, 我正在尝试访问它,

    [Embed(source="hello_world.png")]
        [Bindable]
        public var hello_world:Class;

        init()
    {
.................

        imageID.source = new hello_world();
....................
    }

But the image doesnt get displayed. 但是图像没有显示。

So my question is, how do we access the image component declared in the mxml page in the actionscript class. 所以我的问题是,我们如何访问actionscript类的mxml页面中声明的图像组件。

Judging by the answers on AS3 Embed images class and then get these images into another class? 通过对AS3嵌入图像类的答案进行判断,然后将这些图像放入另一个类中? , you just need to cast your hello_world class as a Bitmap : ,您只需要将hello_world类转换为Bitmap

init()
{
.................

    imageID.source = new hello_world() as Bitmap;
....................
}

try this 尝试这个

imageID.source = hello_world; imageID.source = hello_world;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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