0

我想在我的 Flash SWF 文件中将http://www.flash-mx.com/images/image1.jpg图像显示为缩略图框。为此,我在我的 Flash 电影中使用了一个 Loader 控件,并将其命名为my_thumb,然后将代码编写为:

 _parent.my_thumb.contentPath = "http://www.flash-mx.com/images/image1.jpg";

但是在我的闪存代码中添加上述行后,我收到以下错误。

---------------------------
Flash Player
---------------------------
A script in this movie is causing Flash Player to run slowly.  
If it continues to run, your computer may become unresponsive.  
Do you want to abort the script?
---------------------------
Yes   No   
---------------------------

如果我从我的代码中删除上面的行,那么它工作正常,没有问题。

我无法弄清楚为什么会发生这种情况。我是 Flash 的初学者,对这类错误不太了解。

请检查!

谢谢

4

3 回答 3

1

您所做的错误是您试图使用 AS3 代码在 AS2 中执行某些操作。(contentPath 特定于 AS3)

为了在 AS2 中加载图片,最好使用 MovieClipLoader 类而不是 loadMovie。MovieClipLoader 让您跟踪加载进度,并且它还可以告诉您何时可以访问特定属性,如 _width 和 _height。

这是执行上述操作的脚本。只需将其粘贴到新的 AS2 Fla 中并运行即可。希望它在您学习 Flash 的过程中有所帮助并祝您好运!:)

var container:MovieClip = createEmptyMovieClip("container", getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader(); 
var listener:Object = new Object();

mcLoader.loadClip("http://www.flash-mx.com/images/image1.jpg", container);

listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void 
{ trace(target + ".onLoadProgress with " + bytesLoaded + " bytes of " + bytesTotal); }

listener.onLoadInit = function(target:MovieClip):Void 
{ trace("The picture has been loaded, now you can access information about it like width and height");
trace(container._width+" "+container._height); 
//or 
trace(target._width+" "+target._height) }
mcLoader.addListener(listener);
于 2009-11-24T02:17:35.370 回答
1
var url:String = "http://www.helpexamples.com/flash/images/image2.jpg";
var movieClip:MovieClip = createEmptyMovieClip("movieClip", 0);
movieClip.loadMovie(url);

movieClip._x=200;
movieClip._y=200;

function onEnterFrame(){
    //trace(movieClip._width);
    //trace(movieClip._height);
    if (movieClip._width!=0){
        setDimension(movieClip,100,100);
        delete onEnterFrame;
    }
}

function setDimension(mc:MovieClip,w:Number,h:Number){
    mc._width=w;
    mc._height=h;
}
于 2009-11-25T04:17:41.093 回答
0

我对AS2不熟悉,但是这个页面说该contentPath属性必须是

指示要加载到加载器中的文件的绝对或相对 URL 的字符串。相对路径必须相对于加载内容的 SWF 文件。URL 必须与加载的 SWF 文件位于同一子域中。


您可以使用loadMovie在 ActionScript-2 中加载外部图像。在 AS3 中使用Loader类。

于 2009-11-23T15:23:43.830 回答