加载外部SWF - 尺寸不正确 [英] Loading an external swf - dimensions not correct

查看:247
本文介绍了加载外部SWF - 尺寸不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主SWF文件。它与实例名mc_external_swf一个简单的空影片剪辑。

I have a main swf file. It has a simple empty movieclip with instance name mc_external_swf.

现在我使用的文档类加载外部swf文件。外部文件载荷和是可见的,但其尺寸不恰当的movieclip conatiner内,一些从外部SWF的东西是重叠的movieclip容器之外。看看下面的图片。

Now I use the document class to load an external swf file. The external file loads and is visible, but its dimensions are not fitting inside the movieclip conatiner, some of the stuff from the external swf is overlapping outside of the movieclip container. Look in the image below.

下面是用于加载外部swf文件的code。

Here is the code used to load the external swf file.

    var _swfLoader:Loader;
    var _swfContent:MovieClip;

    function goToPlay(e:MouseEvent=null):void
    {
        loadSWF("agameFLA.swf");
    }       


    public function loadSWF(path:String):void 
    {
       var _req:URLRequest = new URLRequest();
       _req.url = path;

       _swfLoader = new Loader();
       setupListeners(_swfLoader.contentLoaderInfo);

       _swfLoader.load(_req);
    }

    function setupListeners(dispatcher:IEventDispatcher):void 
    {
       dispatcher.addEventListener(Event.COMPLETE, addSWF);
    }

    function addSWF(event:Event):void 
    {
       event.target.removeEventListener(Event.COMPLETE, addSWF);
       event.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);
       _swfContent = event.target.content;
       mc_external_swf.addChild(_swfContent);
    }

下面是外部文件本身code - (它的文档类)

Here is the code of the External File itself - (Of its Document Class)

package
{
import away3d.cameras.Camera3D;
import away3d.cameras.lenses.PerspectiveLens;
import away3d.containers.ObjectContainer3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.controllers.HoverController;
import away3d.entities.Mesh;
import away3d.materials.ColorMaterial;
import away3d.primitives.CubeGeometry;

import flash.display.MovieClip;

public class Main extends MovieClip
{
    public var _view : View3D;
    private var _scene:Scene3D;
    private var _camera : Camera3D;
    private var _hoverController:HoverController;

    private var _container:ObjectContainer3D;
    private var _cube:CubeGeometry;
    private var _cubeMaterial:ColorMaterial;
    private var _cubeMesh:Mesh;

    public function Main()
    {   
        addEventListener(Event.ADDED_TO_STAGE,init);
    }

    private function init(e:Event):void
    {
        removeEventListener(Event.ADDED_TO_STAGE,init);
        iniScene();
        iniObjects();
    }

    private function iniScene():void
    {           
        _scene = new Scene3D();

        _view = new View3D();
        _view.backgroundColor = 0x666666;
        _view.antiAlias = 4;

        _camera= new Camera3D();
        _camera.lens = new PerspectiveLens(60);
        _hoverController = new HoverController(_camera, null, 180, 0);
        _hoverController.distance = 400;
        _hoverController.steps = 16;
        _view.camera = _camera;

        this.addChild(_view);
    }

    private function iniObjects():void
    {
        _container = new ObjectContainer3D();
        _cube = new CubeGeometry(100, 100, 100, 20, 20, 20);

        _cubeMaterial = new ColorMaterial(0x0000FF);

        _cubeMesh = new Mesh(_cube, _cubeMaterial);
        _cubeMesh.mouseEnabled = true;
        _container.addChild(_cubeMesh);
        _view.scene.addChild(_container);
        this.addEventListener(Event.ENTER_FRAME, _onEnterFrame);
        _onResize();
    }

    private function _onResize(e:Event=null):void
    {
        _view.width = stage.stageWidth;
        _view.height = stage.stageHeight;
    }

    private function _onEnterFrame(e:Event):void
    {
        _view.render();
    }
}

}

这可能发生在Away3D的开发库。我试图加载其他主权财富基金,但他们很好适应。但这个SWF尤其不适合在影片剪辑容器。我认为,它已得到事做view3d在Away3D中,但我不知道。

It might be happening to the away3d library. I have tried to load other swfs but they fit in well. But this swf in particular does not fit in the movieclip container. I think it has got something to do with view3d in away3d but I am not sure.

推荐答案

一切,我所看到的已包括以下code。在主类上的Stage3D(或如Away3D中图书馆)教程:

All the tutorials on Stage3D (or libraries such as Away3D) that i have seen have included the following code in the main class:

public function Main()
{
    //wait until stage object is ready
    addEventListener(Event.ADDED_TO_STAGE, addedHandler);
} 

private function addedHandler(event:Event):void
{
    removeEventListener(Event.ADDED_TO_STAGE, addedHandler);
    stage.align = "TL"; //or use StageAlign.TOP_LEFT;
    stage.scaleMode = "noScale"; //or use StageScaleMode.NO_SCALE;
}

这将阻止瑞士法郎结垢。

It will stop the swf from scaling.

这篇关于加载外部SWF - 尺寸不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆