zoukankan      html  css  js  c++  java
  • 使用Loader,运行时加载图片

    BitmapImage只能在使用@Embed位图,要想在运行时加载,可以参考下面的代码

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
     3                xmlns:s="library://ns.adobe.com/flex/spark" 
     4                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
     5                creationComplete="application1_creationCompleteHandler(event)">
     6     
     7     <fx:Script>
     8         <![CDATA[
     9             import mx.controls.Alert;
    10             import mx.events.FlexEvent;
    11 
    12             protected function application1_creationCompleteHandler(event:FlexEvent):void
    13             {
    14                 var loader:Loader = new Loader();
    15                 loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoaderComplete);
    16                 loader.load(new URLRequest("assets/google.png"));
    17             }
    18             
    19             private function handleLoaderComplete(event:Event):void
    20             {
    21                  var bmp:Bitmap = LoaderInfo(event.target).content as Bitmap;
    22                 bf.source = bmp; 
    23             }
    24             
    25         ]]>
    26     </fx:Script>
    27     
    28     <fx:Declarations>
    29         <!-- 将非可视元素(例如服务、值对象)放在此处 -->
    30     </fx:Declarations>
    31     
    32     <s:layout>
    33         <s:VerticalLayout />
    34     </s:layout
    35     
    36     <s:Graphic>
    37         <s:Group>
    38             <s:Ellipse width="300" height="300">
    39                 <s:fill>
    40                     <s:BitmapFill id="bf" fillMode="repeat"/>
    41                 </s:fill>
    42                 
    43             </s:Ellipse>
    44         </s:Group>
    45     </s:Graphic>
    46     
    47     
    48 </s:Application>
  • 相关阅读:
    linux strace 命令详解
    Redis执行Lua脚本示例
    getconf
    rc.sysinit 解析
    Linux系统启动内幕
    syslinux 和 grub
    isolinux.cfg 文件是干什么的
    C++中构造函数调用构造函数
    static和extern的作用域--题目
    构造函数与析构函数不能被继承
  • 原文地址:https://www.cnblogs.com/iihe602/p/2440631.html
Copyright © 2011-2022 走看看