flash读取XML 背景自动适应大小

简介: var bg = new Object();bg.bgdoc_xml = new XML();bg.parse_XML = function() {    function displayXML() {        if (bg.
img_a6339ee3e57d1d52bc7d02b338e15a60.gif var  bg  =   new  Object();
img_a6339ee3e57d1d52bc7d02b338e15a60.gifbg.bgdoc_xml 
=   new  XML();
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gifbg.parse_XML 
=   function ()  img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
function displayXML() img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
if (bg.bgdoc_xml == undefined) img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            trace(
"..undefined");
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
if (bg.bgdoc_xml.loaded == falseimg_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            trace(
"loaded false");
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        }
 else img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
//清除从 setInterval() 的调用
img_33d02437d135341f0800e3d415312ae8.gif
            clearInterval(rep_int);
img_33d02437d135341f0800e3d415312ae8.gif            
//trace("BgXml Load success");
img_33d02437d135341f0800e3d415312ae8.gif
            play();
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_105a1e124122b2abcee4ea8e9f5108f3.gif    }

img_33d02437d135341f0800e3d415312ae8.gif    bg.bgdoc_xml.ignoreWhite 
= true;
img_33d02437d135341f0800e3d415312ae8.gif    bg.bgdoc_xml.load(
"background.xml");
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    bg.bgdoc_xml.onLoad 
= function(success) img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
if (!success) img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            trace(
"background.xml false");
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        }
 else img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
//每隔200毫秒调用displayXML
img_33d02437d135341f0800e3d415312ae8.gif
            rep_int = setInterval(displayXML, 200);
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_105a1e124122b2abcee4ea8e9f5108f3.gif    }
;
img_05dd8d549cff04457a6366b0a7c9352a.gif}
;
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
//
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gif
bg.Init  =   function ()  img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_33d02437d135341f0800e3d415312ae8.gif    
//trace("img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gifbg.Init");
img_33d02437d135341f0800e3d415312ae8.gif
    bg.folder = bg.bgdoc_xml.firstChild.attributes.folder;
img_33d02437d135341f0800e3d415312ae8.gif    bg.path_array 
= new Array();
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
for (var i = 0; i<bg.bgdoc_xml.firstChild.childNodes.length; i++img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        bg.path_array.push(bg.folder
+bg.bgdoc_xml.firstChild.childNodes[i].attributes.url);
img_105a1e124122b2abcee4ea8e9f5108f3.gif    }

img_33d02437d135341f0800e3d415312ae8.gif    bg.nowOrder 
= random(bg.path_array.length);
img_33d02437d135341f0800e3d415312ae8.gif    bg.start 
= true;
img_05dd8d549cff04457a6366b0a7c9352a.gif}
;
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gifbg.show 
=   function ()  img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_33d02437d135341f0800e3d415312ae8.gif    
//trace("img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gifbg.show");
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif
    if (bg.nowOrder == undefined) img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        bg.nowOrder 
= 0;
img_105a1e124122b2abcee4ea8e9f5108f3.gif    }

img_33d02437d135341f0800e3d415312ae8.gif    
var bg_mc = _root.Content_bg;
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
if (bg_mc == undefined) img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        gotoAndPlay(
"Loadbg");
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    }
 else img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        bg_mc.bg_content_mc.loadMovie(bg.path_array[bg.nowOrder]);
img_105a1e124122b2abcee4ea8e9f5108f3.gif    }

img_05dd8d549cff04457a6366b0a7c9352a.gif}
;
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gifbg.showPrev 
=   function ()  img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_33d02437d135341f0800e3d415312ae8.gif    _root.bg.nowOrder
--;
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
if (_root.bg.nowOrder<0img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        _root.bg.nowOrder 
= _root.bg.path_array.length-1;
img_105a1e124122b2abcee4ea8e9f5108f3.gif    }

img_33d02437d135341f0800e3d415312ae8.gif    bg.show();
img_05dd8d549cff04457a6366b0a7c9352a.gif}
;
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gifbg.showNext 
=   function ()  img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_33d02437d135341f0800e3d415312ae8.gif    _root.bg.nowOrder
++;
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
if (_root.bg.nowOrder>_root.bg.path_array.length-1img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        _root.bg.nowOrder 
= 0;
img_105a1e124122b2abcee4ea8e9f5108f3.gif    }

img_33d02437d135341f0800e3d415312ae8.gif    bg.show();
img_05dd8d549cff04457a6366b0a7c9352a.gif}
;
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gifbg.Brightness 
=   function ()  img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_33d02437d135341f0800e3d415312ae8.gif    
var mark_mc = _root.Content_bg.bgmark_mc;
img_33d02437d135341f0800e3d415312ae8.gif    mark_mc.play();
img_05dd8d549cff04457a6366b0a7c9352a.gif}
;
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gifff 
=   function  ()  img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_33d02437d135341f0800e3d415312ae8.gif    
var loader = _root.Loader_mc;
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    bg_mc.onEnterFrame 
= function() img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif        
var Total = this.bg_content_mc.getBytesTotal();
img_33d02437d135341f0800e3d415312ae8.gif        
var Loaded = this.bg_content_mc.getBytesLoaded();
img_33d02437d135341f0800e3d415312ae8.gif        
var percent = int(Loaded/Total*100);
img_33d02437d135341f0800e3d415312ae8.gif        loader.gotoAndStop(percent);
img_33d02437d135341f0800e3d415312ae8.gif        trace(
"Loaded:"+percent);
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
if (percent>=100img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
this.onEnterFrame = undefined;
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
if (bg.start) img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif                bg.start 
= false;
img_33d02437d135341f0800e3d415312ae8.gif                _root.gotoAndPlay(
"playMenu");
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_105a1e124122b2abcee4ea8e9f5108f3.gif    }
;
img_05dd8d549cff04457a6366b0a7c9352a.gif}
;
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
var  bgListener  =   new  Object();
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gifbgListener.onResize 
=   function ()  img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_33d02437d135341f0800e3d415312ae8.gif    
//trace("Stage size is now "+Stage.width+" by "+Stage.height);
img_33d02437d135341f0800e3d415312ae8.gif
    resizeBg();
img_05dd8d549cff04457a6366b0a7c9352a.gif}
;
img_a6339ee3e57d1d52bc7d02b338e15a60.gifStage.addListener(bgListener);
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gif
function  resizeBg()  img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_33d02437d135341f0800e3d415312ae8.gif    
var bg_mc = _root.Content_bg;
img_33d02437d135341f0800e3d415312ae8.gif    
var bgWidth = bg_mc.bg_content_mc._width;
img_33d02437d135341f0800e3d415312ae8.gif    
var bgHeight = bg_mc.bg_content_mc._height;
img_33d02437d135341f0800e3d415312ae8.gif    
//scale the background to resize
img_33d02437d135341f0800e3d415312ae8.gif
    var maxScale = Math.max(Stage.width*bg_mc.bg_content_mc._xscale/bgWidth, Stage.height*bg_mc.bg_content_mc._yscale/bgHeight);
img_33d02437d135341f0800e3d415312ae8.gif    bg_mc.bg_content_mc._xscale 
= bg_mc.bg_content_mc._yscale=maxScale;
img_05dd8d549cff04457a6366b0a7c9352a.gif}

img_a6339ee3e57d1d52bc7d02b338e15a60.gif
相关文章
|
11月前
|
SQL XML Java
解决关于在idea使用Mybatis时, 编写xml的动态sql语句背景高亮不舒服问题
解决关于在idea使用Mybatis时, 编写xml的动态sql语句背景高亮不舒服问题
1098 0
|
XML SQL Java
解决2022.3.1版本中 IDEA中 XML文件屎黄色背景 的方法
解决2022.3.1版本中 IDEA中 XML文件屎黄色背景 的方法
519 0
|
XML JavaScript 前端开发
【前端】白天/黑夜主题切换:JS读取XML预设主题实现黑白主题切换
【前端】白天/黑夜主题切换:JS读取XML预设主题实现黑白主题切换
192 0
【前端】白天/黑夜主题切换:JS读取XML预设主题实现黑白主题切换
|
XML 数据格式 Python
XML转CSV读取对应所有数据(tkinter工具)
代码段:处理xml标签和标签名的数据读取
138 0
XML转CSV读取对应所有数据(tkinter工具)
|
XML JavaScript 数据处理
【目标检测】一文干翻xml文件的读取
【目标检测】一文干翻xml文件的读取
【目标检测】一文干翻xml文件的读取
|
XML 数据格式
hutool读取xml文件
hutool读取xml文件
|
XML 存储 Java
java积累——dom4j读取xml文件
java积累——dom4j读取xml文件
270 0
|
XML 消息中间件 运维
Sring源码解析(一)Spring是怎么读取配置Xml文件的
1#Spring读取配置文件 ##Document 在XmlBeanDefinitionReader.doLoadBeanDefinitions(InputSource inputSource, Resource resource)方法中将Xml文件转换成Document对象;Document doc = doLoadDocument(inputSource, resource);
Sring源码解析(一)Spring是怎么读取配置Xml文件的
|
XML Linux 数据格式
python读取linux上的xml文件
python远程读取linxu服务器上的xml文件
152 0
|
XML Java 数据格式
Spring源码(二-3)-XML文件的读取-factory-method的使用
Spring 可以通过 factory-method 实例化对象。factory-method方式是 Spirng 实例对象的方式之一。
971 2