[]swf转成H5资源显示超出原有范围
swf显示是正常的,用的LayaFlash编译之后图片超出设定范围 且载入的data.swf尺寸跟原来不同,不方便调整大小及位置来适配不同设备,麻烦帮忙看下,谢谢啦,贴上代码。
package
{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.Capabilities;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function setWindowFullSize() : void
{
var stageW:int = 0;
var stageH:int = 0;
__JS__( 'stageW = Laya.window.innerWidth;' );
__JS__( 'stageH = Laya.window.innerHeight;' );
(stageW > 0) && IFlash.setSize(stageW, stageH);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.scaleMode = StageScaleMode.NO_SCALE;//设置舞台的缩放模式和对齐方式
stage.align = StageAlign.TOP_LEFT;
//setWindowFullSize();
IFlash.setOrientationEx(1); //是否为横屏模式,默认横屏 @param value 0 竖屏 1 横屏
IFlash.setBgcolor("#ffffff"); //背景色
IFlash.showInfo(true); //是否显示帧率
loadAsset();
}
private function loadAsset():void
{
var context:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain)
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,assetLoadComplete);
loader.load(new URLRequest("res/data.swf"),context);
}
private function assetLoadComplete(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
loaderInfo.removeEventListener(Event.COMPLETE, assetLoadComplete);
var content:MovieClip = loaderInfo.content as MovieClip;
if (!content)
{
trace("content is null.");
return;
}
var appDomain:ApplicationDomain = ApplicationDomain.currentDomain;
if (!appDomain || !appDomain.hasDefinition("Dragon_5"))
{
trace("Dragon_5 is null.");
return;
}
content.scaleX = stage.height/1334;
content.scaleY = stage.height/1334;
content.x = 0;
content.y = 0;
addChild(content);
content.play();
setInterval(function(){content.nextFrame()},50)
}
}
}
package
{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.Capabilities;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function setWindowFullSize() : void
{
var stageW:int = 0;
var stageH:int = 0;
__JS__( 'stageW = Laya.window.innerWidth;' );
__JS__( 'stageH = Laya.window.innerHeight;' );
(stageW > 0) && IFlash.setSize(stageW, stageH);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.scaleMode = StageScaleMode.NO_SCALE;//设置舞台的缩放模式和对齐方式
stage.align = StageAlign.TOP_LEFT;
//setWindowFullSize();
IFlash.setOrientationEx(1); //是否为横屏模式,默认横屏 @param value 0 竖屏 1 横屏
IFlash.setBgcolor("#ffffff"); //背景色
IFlash.showInfo(true); //是否显示帧率
loadAsset();
}
private function loadAsset():void
{
var context:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain)
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,assetLoadComplete);
loader.load(new URLRequest("res/data.swf"),context);
}
private function assetLoadComplete(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
loaderInfo.removeEventListener(Event.COMPLETE, assetLoadComplete);
var content:MovieClip = loaderInfo.content as MovieClip;
if (!content)
{
trace("content is null.");
return;
}
var appDomain:ApplicationDomain = ApplicationDomain.currentDomain;
if (!appDomain || !appDomain.hasDefinition("Dragon_5"))
{
trace("Dragon_5 is null.");
return;
}
content.scaleX = stage.height/1334;
content.scaleY = stage.height/1334;
content.x = 0;
content.y = 0;
addChild(content);
content.play();
setInterval(function(){content.nextFrame()},50)
}
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
cuixueying
赞同来自:
zjchenjia
赞同来自: