【问题标题】:How do I specify the height and width of a external swf? AS3如何指定外部 swf 的高度和宽度? AS3
【发布时间】:2011-05-06 04:32:10
【问题描述】:

我想将一个外部 swf 文件加载到我的项目中。我的项目比我正在加载的项目小得多,我需要使外部 swf 文件更小以适应。每当我添加 myLoader.width 和 myLoader.height 时,都无法看到该项目。如果我把它拿走 myLoader.width 和 myLoader,项目可以正常加载,但它太大了。

这是我的代码,

stop();
home_btn.addEventListener(MouseEvent.CLICK, ClickButton2);
calm_btn.addEventListener(MouseEvent.CLICK, ClickButton2);
linden_btn.addEventListener(MouseEvent.CLICK, ClickButton2);
moving_btn.addEventListener(MouseEvent.CLICK, ClickButton2);

var myLoader:Loader=new Loader();

var xPos:Number = 45;

var yPos:Number = 85;

function ClickButton2(Event:MouseEvent):void

{

if(Event.target==home_btn)

{
    gotoAndStop("home");
}

else if(Event.target==calm_btn)
{
    gotoAndStop("calm");
    var myURL:URLRequest=new URLRequest("Project 2 Scott Parker FINAL.swf");
    myLoader.load(myURL);
    myLoader.x = xPos;
    myLoader.y = yPos;
    myLoader.width = 100;
    myLoader.height = 100;
    addChild(myLoader);
}

谢谢

【问题讨论】:

    标签: flash height width external loading


    【解决方案1】:

    我想你想要 myLoader.content.width = 100;

    http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html

    *编辑

    function ClickButton2(event:MouseEvent):void
    
    {
    
    if(event.target==home_btn)
    
    {
        gotoAndStop("home");
    }
    
    else if(event.target==calm_btn)
    {
        gotoAndStop("calm");
        var myURL:URLRequest=new URLRequest("Project 2 Scott Parker FINAL.swf");
        myLoader.load(myURL);
        myLoader.x = xPos;
        myLoader.y = yPos;
    
        myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(){
            myLoader.content.width = 100;
            myLoader.content.height= 100;
        });
    
        addChild(myLoader);
    }
    

    【讨论】:

    • 在尚未加载时尝试调整大小时会出现此错误。请尝试在我更新的答案中使用代码 sn-p...
    • 抱歉,我已经更新了代码 sn-p 以包含更多您的代码,以便您查看它的去向。
    • 我复制并粘贴了您在我的代码中输入的内容,我收到此错误:1119: Access of possible undefined property COMPLETE through an reference with static type flash.events:MouseEvent.
    • 那是因为你的 ClickButton2 有一个名为 Event 的参数。这应该重命名为小写,这样它就不会与事件包名称冲突。我将更新我的代码示例
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    相关资源
    最近更新 更多