简体   繁体   中英

assign swf as image source in flex at runtime

In Flex, how to assign swf as image source at runtime, not embedding it .

[Bindable] public var myImg:String;

<mx:Image id="intImg" source="{myImg}" width="96%" height="96%" />

In my application, I fetch image url dynamically from a web service call, and assign it to "myImg".

But until I don't get the response from the web service call, I want to show a loader swf in image control above. I assigned something like:

myImg = "assets/AS3.swf";

and the path of swf is correct, but it doesn't show up.


UPDATE:

The code I've shown above works perfectly in a Flex 3 app but the swf does not show up in a Flex 4 app. Is it because Image control has dropped the support for swf in Flex 4?

Please help me out.

thanks

Use SWFLoader to load SWFs, Image is made for Images...

Are you absolutely sure that your path is correct? Because it should work.

Remember that the path you write (assets/AS3.swf) is relative to the location of your application swf file. So for instance if you're debugging in FlashBuilder/FlexBuilder the file should be located in

[yourprojectdirectory]/bin-debug/assets/AS3.swf

Non-embedded files are not automatically copied to the bin-debug folder (or the bin-release folder for that matter). So you have to do it manually.

You can use a web debugging proxy - like Charles - to see whether the file is found in the path you are using.

Did you accidentally refactor mx:Image to s:Image in your Flex 3 to Flex 4.5 migration?

For Spark Image, it could be that you need to reference the symbol name in the SWF.

I find this works:

<s:Image source="@Embed(source='path.swf', symbol='name')" ...

Seems like a bad practice, though - unlike mx:Image which would load the SWF natively, Spark Image is intended for bitmap data.

For Flex 4 , I think ONLY SWF with AS3 (AVM2*) support was dropped. Try with AS1 & AS2 , that run within AVM1*

* AVM (ActionScript Virtual Machine)

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