外部影片剪辑仅在调整窗口大小时可见

发布于 2024-10-25 03:00:07 字数 424 浏览 6 评论 0原文

我正在 SWF 中加载外部影片剪辑。舞台比例模式为“无比例”,舞台对齐为左上角。我正在 OnResize 事件中使用以下内容将移动剪辑的大小调整为父影片剪辑的实际高度和宽度:

object.x = stage.x;
object.y = stage.y;
object.width = stage.stageWidth;
object.height = stage.stageHeight;

但它不起作用。两个要点:

  1. 早期,当使用 10 之前版本的 Flash Player 时,它可以正常工作
  2. 。现在,只有当我调整窗口大小时,它才可以工作。我只是不明白为什么它会造成问题。

任何形式的帮助将不胜感激,因为我就是因为这个而被阻止的。我不想使用舞台的精确配合比例模式。

谢谢!

I am loading an external movie clip in my SWF. The stage scale mode is "no scale" and stage align is TOP LEFT. I am resizing move clip to the actual height and width of parent movie clip using following in OnResize event:

object.x = stage.x;
object.y = stage.y;
object.width = stage.stageWidth;
object.height = stage.stageHeight;

But it's not working. Two important points:

  1. It was working earlier when was using Flash Player older than 10.
  2. Now, it works only when I resize the window. I just can't understand why it's creating the problem.

Any help of any sort would be highly appreciated as I am blocked just coz of this. I don't want to use exact fit scale mode of the stage.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对岸观火 2024-11-01 03:00:07

请记住,object.height 和 object.width 指的是对象上的活动内容,具体取决于您导入它的方式:

    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.display.MovieClip;

    function startLoad()
    {
    var mLoader:Loader = new Loader();
    var mRequest:URLRequest = new URLRequest("test.swf");
    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
    mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    mLoader.load(mRequest);
    }

    function onCompleteHandler(loadEvent:Event)
    {
            var object:MovieClip = loadEvent.currentTarget.content;
            object.x = stage.x;
            object.y = stage.y;
            trace(object.width);
            trace(stage.stageWidth);
            object.width = stage.stageWidth;
            trace(object.height);
            trace(stage.stageHeight);
            //object.height = stage.stageHeight;

            addChild(object);


}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();

上面的代码可以工作,但您可能会将宽度拉伸到内容被拉伸的程度场景,追踪宽度和高度。

编辑:

对于 YouTube 来说,它会是这样的:

var loader:Loader = new Loader(); - global variable

function initialzer(){
       loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
       loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
}

private function onLoadInit(event:Event){
    addChild(loader);
    loader.content.addEventListener("onReady", onPlayerReady);
    loader.content.addEventListener("onError", onPlayerError);

}

function onPlayerReady(event:Event):void {
    player = loader.content;
    player.width = 111;
    player.height = 111;
}

Remember that the object.height and object.width refers to the active content on the object depending on how you're importing it:

    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.display.MovieClip;

    function startLoad()
    {
    var mLoader:Loader = new Loader();
    var mRequest:URLRequest = new URLRequest("test.swf");
    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
    mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    mLoader.load(mRequest);
    }

    function onCompleteHandler(loadEvent:Event)
    {
            var object:MovieClip = loadEvent.currentTarget.content;
            object.x = stage.x;
            object.y = stage.y;
            trace(object.width);
            trace(stage.stageWidth);
            object.width = stage.stageWidth;
            trace(object.height);
            trace(stage.stageHeight);
            //object.height = stage.stageHeight;

            addChild(object);


}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();

That code above works, but you may be stretching the width to the point where the content is being stretched out of the scene, trace the width and height.

EDIT:

for youtube it would be something like this:

var loader:Loader = new Loader(); - global variable

function initialzer(){
       loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
       loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
}

private function onLoadInit(event:Event){
    addChild(loader);
    loader.content.addEventListener("onReady", onPlayerReady);
    loader.content.addEventListener("onError", onPlayerError);

}

function onPlayerReady(event:Event):void {
    player = loader.content;
    player.width = 111;
    player.height = 111;
}
凉城已无爱 2024-11-01 03:00:07

您可能在将对象添加到舞台之前应用转换,因此舞台引用为 null 且/或它的属性为 null。您应该将事件侦听器添加到对象 Event.ADDED_TO_STAGE,然后在事件的回调中应用您的转换。此外,您不需要通过 object.stage 访问 stage 对象,stage 应该是一个静态实体,您可以从对象内部或外部调用它。如果您无法通过在应用此转换的范围内简单地键入“stage”来访问该阶段,那么这可能是问题的原因。就像我说的,尝试使用 ADDED_TO_STAGE 事件,在该回调中应用转换,如果我是对的,一切都应该没问题。此外,当您尝试像上面发布的那样强制转换对象时,请使用“as”关键字。示例:

var object:MovieClip = loadEvent.currentTarget.content as MovieClip;

您关于 YouTube 播放器“不支持此方法”的说法实际上没有意义,因为这与 YouTube 或任何其他外部 API 无关。强制转换/类型转换是一种编程语言功能。该语句成立的唯一情况是,youtube 播放器与 MovieClip 对象没有共同的内在性,在这种情况下,您会在运行时(在某些情况下甚至可能是编译时)收到类型强制错误,告诉您只需无法将一个对象转换为完全不同的对象。无论如何希望这会有所帮助。

You're probably applying the transformation before the object has been added to the stage and thus, the stage reference is null and or its properties are null. You should add the event listener to the object Event.ADDED_TO_STAGE and then within the callback of the event, apply your transformations. Also you don't need to access the stage object through object.stage, the stage should be a static entity that you can call from either within the object or outside of it. If you cannot access the stage by simply typing "stage" from within the scope where you are applying this transformation then this would probably be the cause of the issue. Like I said, try using the ADDED_TO_STAGE event, apply the transformations within that callback and everything should be okay if I'm right. Also when you're trying to cast an object like you've posted above, use the "as" keyword. Example:

var object:MovieClip = loadEvent.currentTarget.content as MovieClip;

Your statement that the youtube player "doesn't support this method" doesn't really make sense, since this had nothing to do with youtube or any other external API. Casting/type conversion is a programming language feature. The only case where this statement would be true is if the youtube player had no common inhertence with the MovieClip object, in which case you'd get a type coercion error at runtime (maybe even compile time in some instances) telling you that you simply cannot cast an object as a completely different object. Anyway hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文