博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Flex动态获取flash资源库文件
阅读量:4062 次
发布时间:2019-05-25

本文共 7570 字,大约阅读时间需要 25 分钟。

有几种方式 在这里介绍两种

1. 给一个flash资源文件写个资源外壳

例如 在一个包含a 和b两个元件的flash文件中写个as类

public class Wipper

{

      [Embed(source="a")]

      public var A:Class;

      [Embed(source="a")]

      public var B:Class;

}

 

将此类发布到包含a,b元件的swf中

flex可以直接访问A 和 B了

 

2 .

1.命名前必须将所要用到的整合组件放置flash主场景中,然后在时间轴第一帧上脚本代码指定引用元件,如:this. FR;指引操作如下:

⑴.   以原来的脸部组件为例 打开flash 确认打开的是否为当前文件

 

(2).打开时间轴(TIMRLINE

 

(3).右键点击最上面一层的第一帧选择Actions

 

(4).出现以下界面

                       

(5). 选择代码指引的按钮(带十字的圆圈),出现下面弹出框

                 

(6).选择你要命名的元件,单击(如:女性前右基础眼睛)

                 

(7).点击Rename                                                           

(8),填写下面命名规则中相对应的名字(如:FR)点击OK

 

(9).选中刚命名过的元件,双击或者点击OK

 

      (10).在此行后面加分号,回车

                                 

      (11).重复(3)到(9)继续给其他元件命名。

 

flex中可用此自定义组件访问

 

package{

 import flash.display.BitmapData;
 import flash.display.DisplayObject;
 import flash.display.MovieClip;
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.geom.Matrix;
 
 import fw.ui.events.UIEvent;
 
 import mx.events.ResizeEvent;
 
 public class FWTransparentImage extends FWImage
 {
  private static const EFFECIENCY_SAVE_FACTOR:uint = 20;
  
  private var ht:Sprite = new Sprite();
  
  public function FWTransparentImage()
  {
   super();
   
   addChild(ht);
   
   hitArea = ht;
   ht.visible = false;
   ht.mouseEnabled = false;
   
   //addEventListener(Event.COMPLETE, completeHandler, false, 99, true);
   addEventListener(ResizeEvent.RESIZE, completeHandler, false, 99, true);
   addEventListener(UIEvent.IMAGE_RELOAD, completeHandler, false, 99, true);
  }
  
  [Inspectable(defaultValue="true")]
  public var staticContent:Boolean = true;
  
  private var _contentChanged:Boolean = false;
  
//  
//  override public function set movieClipName(value:String):void
//  {
//   super.movieClipName = value;
//   _contentChanged = true;
//  }
//  
//  override public function set source(value:Object):void
//  {
//   super.source = value;
//   _contentChanged = true;
//  }
  
  private function completeHandler(e:Event):void
  {
   //trace("******", e.type, "*******");
   _contentChanged = true;
   
   if (!staticContent
    && content
    && content.loaderInfo.contentType == "application/x-shockwave-flash"
    && content is MovieClip
    )
   {
    MovieClip(content).addEventListener(Event.ENTER_FRAME, refreshFrameHandler);
   }
   
   //updateHitArea();
  }
  
  public var monitorRate:uint = 24;
  private var _framed:uint = 0;
  private function refreshFrameHandler(e:Event):void
  {
   if (_framed++ < monitorRate) return;
   _framed = 0;
   _contentChanged = true;
   
   //updateHitArea();
  }
  
  override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
  {
   super.updateDisplayList(unscaledWidth, unscaledHeight);
   //return;
//  private function updateHitArea():void
//  {
   if (mouseEnabled && _contentChanged && content)
   {
    _contentChanged = false;
    
    var factor:uint =
     Math.min(
      Math.max(Math.min(content.width, content.height)/5, 2),
      EFFECIENCY_SAVE_FACTOR
      );
    
    var container:DisplayObject = content.parent as DisplayObject;
    var bmp:BitmapData = new BitmapData(container.width, container.height, true, 0x00000000);
    var matrix:Matrix = new Matrix();
    matrix.scale(container.scaleX, container.scaleY);
    bmp.draw(container, matrix);
    
    // redraw hit area
    with(ht.graphics)
    {
     clear();
     beginFill(0x000000);
     for (var x:int=0; x<container.width; x+=factor)
     {
      for (var y:int=0; y<container.height; y+=factor)
      {
       if (bmp.getPixel32(x, y))
       {
        drawRect(x, y, factor, factor);
       }
      }
     }
     endFill();
    }
    
    ht.x = -factor/2, ht.y = -factor/2;
    
    addChild(ht);
   }
  }
 }
}

 

此类继承了 自定义组件

<?xml version="1.0" encoding="utf-8"?>

<mx:SWFLoader xmlns:mx=""
 xmlns:base="fw.base.*"
 mouseChildren="false" mouseEnabled="false"
 >
 <mx:Script>
  <![CDATA[
   import fw.ui.events.UIEvent;
   import fw.events.FWEvent;
   import fw.base.Utils;
   import mx.events.ResizeEvent;
   import fw.base.Logger;
   import fw.comm.ResourceLoader;
   import fw.comm.events.ResourceLoaderEvent;
   
   [Embed(source="/assets/imageAutoload.swf#loadPic")]
   private static const DEFAULT_LOADING:Class;
   [Embed(source="/assets/imageAutoload.swf#errorImage")]
   private static const DEFAULT_ERROR:Class;
   
   [Inspectable(defaultValue="true")]
   public var showErrorImage:Boolean = true;
   
   [Inspectable(defaultValue="false")]
   public var loadChildMovieClip:Boolean = false;
   
   private var _movieClipName:String = "unnamed";
   [Bindable(event="mcNameChanged")]
   public function set movieClipName(value:String):void
   {
    _movieClipName = value;
    loadMovieClip();
    dispatchEvent(new Event("mcNameChanged"));
   }
   public function get movieClipName():String
   {
    return _movieClipName;
   }
   
   public function hasMovieClipName(name:String):MovieClip
   {
    if (
     _movieClipHolder
     && _movieClipHolder.content
     && _movieClipHolder.content.hasOwnProperty(name)
     )
     return _movieClipHolder.content[name] as MovieClip;
    else
     return null;
   }
   
   public function get isBroken():Boolean
   {
    return (super.source == DEFAULT_ERROR);
   }
   
   [Inspectable(defaultValue="false")]
   public var transformable:Boolean = false;
   private var _color:Number;
   public function set color(value:Number):void
   {
    if (value == _color) return;
    if (isNaN(value)) return;
    _color = value;
    
    transformColor();
   }
   public function get color():Number
   {
    return _color;
   }
   
   private var _movieClipHolder:Loader;
   private var _loader:ResourceLoader;
   private var _loading:Boolean = false;
   
   private var _source:Object;
   public override function set source(value:Object):void
   {
    if (_source == value) return;
    _source = value;
    
    if (_source is String)
    {
     _loader = new ResourceLoader();
     _loader.addEventListener(ResourceLoaderEvent.SUCCESS, contentLoadedHandler);
     _loader.addEventListener(ResourceLoaderEvent.ERROR, errorHandler);
     
     super.source = DEFAULT_LOADING;
     currentState = "loading";
     
     _loading = true;
     _loader.load(value as String);
    }
    else
    {
     super.source = _source;
    }
   }
   public override function get source():Object
   {
    return _source;
   }
   
   private function contentLoadedHandler(e:ResourceLoaderEvent):void
   {
    _loader.removeEventListener(ResourceLoaderEvent.SUCCESS, contentLoadedHandler);
    _loader.removeEventListener(ResourceLoaderEvent.ERROR, errorHandler);
    _loading = false;
    
    if (loadChildMovieClip)
    {
     if (_movieClipHolder)
      _movieClipHolder.contentLoaderInfo.removeEventListener(Event.COMPLETE, movieClipLoadedHandler);
     _movieClipHolder = new Loader;
     var context:LoaderContext =
      new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain));
     _movieClipHolder.contentLoaderInfo.addEventListener(Event.COMPLETE, movieClipLoadedHandler);
     _movieClipHolder.loadBytes(e.bytes, context);
    }
    else
    {
     currentState = "";
     super.source = e.bytes;
    }
   }
   
   private function movieClipLoadedHandler(e:Event):void
   {
    currentState = "";
    loadMovieClip();
   }
   
   private function errorHandler(e:ResourceLoaderEvent):void
   {
    Logger.warning("AutoImage loading error for: ", _loader.url);
    
    _loader.removeEventListener(ResourceLoaderEvent.SUCCESS, contentLoadedHandler);
    _loader.removeEventListener(ResourceLoaderEvent.ERROR, errorHandler);
    _loading = false;
    
    if (showErrorImage) super.source = DEFAULT_ERROR;
    else super.source = null;
    currentState = "loading";
   }
   
   private function loadMovieClip():void
   {
    if (_movieClipHolder && _movieClipHolder.content)
    {
     super.source = _movieClipHolder.content[_movieClipName];
     dispatchEvent(new UIEvent(UIEvent.IMAGE_RELOAD));
    }
   }
   
   private function transformColor():void
   {
    if (!isNaN(_color))
    {
     var trans:ColorTransform = new ColorTransform;
     trans.color = _color;
     this.transform.colorTransform = trans;
    }
   }
  ]]>
 </mx:Script>
 <mx:states>
  <mx:State name="loading">
   <mx:SetProperty name="maintainAspectRatio" value="true"/>
   <mx:SetProperty name="scaleContent" value="false"/>
   <mx:SetStyle name="horizontalAlign" value="center"/>
   <mx:SetStyle name="verticalAlign" value="middle"/>
  </mx:State>
 </mx:states>
</mx:SWFLoader>

 

访问可以这么写

<controls:FWTransparentImage id="hat"

  mouseEnabled="false" loadChildMovieClip="true"
  cacheAsBitmap="true" cachePolicy="on"
  x="0" y="0" width="100%" height="100%"
  source="{character.hat.movieClipURL}"
  />

转载地址:http://xucji.baihongyu.com/

你可能感兴趣的文章
从头开始学习jsp(2)——jsp的基本语法
查看>>
使用与或运算完成两个整数的相加
查看>>
备忘:java中的递归
查看>>
Solr及Spring-Data-Solr入门学习
查看>>
python_time模块
查看>>
python_configparser(解析ini)
查看>>
selenium学习资料
查看>>
<转>文档视图指针互获
查看>>
从mysql中 导出/导入表及数据
查看>>
HQL语句大全(转)
查看>>
几个常用的Javascript字符串处理函数 spilt(),join(),substring()和indexof()
查看>>
javascript传参字符串 与引号的嵌套调用
查看>>
swiper插件的的使用
查看>>
layui插件的使用
查看>>
JS牛客网编译环境的使用
查看>>
9、VUE面经
查看>>
关于进制转换的具体实现代码
查看>>
Golang 数据可视化利器 go-echarts ,实际使用
查看>>
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>