简体   繁体   English

在ActionScript中,使用外部SWF填充阶段

[英]In ActionScript, fill stage with external SWF

EDIT: I have since solved this problem by simply reworking my MXML-based app and using the SWFLoader component to get the desired effect, without any reloading necessary. 编辑:此后,我已经解决了这个问题,只需重新设计基于MXML的应用程序并使用SWFLoader组件即可获得所需的效果,而无需重新加载。 This question is therefore no longer an issue for me, but I leave it open for reference. 因此,这个问题对我来说不再是一个问题,但我可以留作参考。


In MXML, I can get the desired effect easily: 在MXML中,我可以轻松获得所需的效果:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  layout="absolute">
  <mx:SWFLoader width="100%" height="100%"
    source="3298.swf"/>
</mx:Application>

It looks like this: 看起来像这样:

(external SWF fills stage) http://www.ubuntu-pics.de/bild/40036/screenshot_028_MSd0UZ.png (外部SWF填充阶段)http://www.ubuntu-pics.de/bild/40036/screenshot_028_MSd0UZ.png

I'm new at ActionScript, though, so I can't quite figure out how to duplicate this without MXML. 但是,我是ActionScript的新手,所以我不太了解如何在没有MXML的情况下复制它。 Here's the relevant class: 这是相关的课程:

package {
  import flash.net.URLRequest;
  import flash.display.DisplayObject;
  import flash.display.Loader;
  import flash.events.Event;

  public class Asset extends Loader {
    public var id:int;
    private var preview:Preview;
    private var swfContent:DisplayObject;
    public var zone:int;

    public function Asset(data:Object) {
      id = data.id;
      zone = data.zone;
    }

    public function loadInto(previewToSet:Preview):void {
      preview = previewToSet;
      var request:URLRequest = new URLRequest(url);
      contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
      load(request);
    }

    private function onCompleteHandler(loadEvent:Event):void {
      swfContent = loadEvent.currentTarget.content;
      swfContent.scaleX = 1;
      swfContent.scaleY = 1;
      preview.addChild(swfContent);
    }

    private function get url():String {
      return id + ".swf";
    }
  }
}

In the loadInto function I give the Asset a sprite to live on, and it starts to load. loadInto函数中,我给Asset提供了一个精灵,它可以继续加载。 I can get pretty close by setting scaleX and scaleY each to 1, but I can't quite figure out why it's not at the top, and why the SWF is just a bit to large. 我可以通过将scaleXscaleY分别设置为1来接近,但是我无法弄清楚为什么它不在顶部,以及SWF有点大。

(external swf slightly off) http://www.ubuntu-pics.de/bild/40040/screenshot_029_4pHKNI.png (外部SWF略微关闭)http://www.ubuntu-pics.de/bild/40040/screenshot_029_4pHKNI.png

How can I duplicate MXML's 100% height and width in pure ActionScript? 如何在纯ActionScript中复制MXML的100%高度和宽度? Is it doable? 可以吗 If not, I have a fallback app in pure MXML, but my implementation there involves loading the SWFs every time I want to add or remove any one of them... it's not perfect. 如果不是这样,我有一个纯MXML的后备应用程序,但是我在那里的实现涉及每次我想添加或删除其中任何一个时都加载SWF ...这并不完美。 So I'd prefer this type of implementation if I can just figure out the sizing issue. 因此,如果我能确定大小问题,我将更喜欢这种类型的实现。

Thanks! 谢谢!

Use the resize event from the stage object and each time the resize event is fired resize the content according to that: 使用resize事件舞台对象和每个时间resize事件被触发根据该调整内容:

stage.addEventListener(Event.RESIZE, onResize);

public function onResize(e:Event):void{
 swfContent.width=stage.stageWidth;
 swfContent.height=stage.stageHeight;
}

try adding 尝试添加

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

to the start of your class then size and place the loaded image to 到课程开始处,然后将加载的图像调整大小并放置到

loadedimage.x = loadedimage.y = 0;
loadedimage.width = stage.stageWidth;
loadedimage.height = stage.stageHeight;

This sound like the anchor point of your swf is not precisely in it's corner. 这听起来像瑞士法郎的锚点不完全在它的角落。 Try offsetting the x and y position in your code, or, even better, modifying the swf to have the anchor point in the corner ? 尝试偏移代码中的x和y位置,或者甚至更好地修改swf以使锚点位于拐角处?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM