Flash CS4:使用“Loader.contentPath”时无响应错误?

时间:2009-11-23 15:06:47

标签: flash adobe actionscript-2 flash-cs4

我想在我的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代码中添加以上行后,我收到了以下错误。

---------------------------
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的初学者,对这些错误并不太了解。

请检查!

由于

3 个答案:

答案 0 :(得分: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);

答案 1 :(得分: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;
}

答案 2 :(得分:0)

我不熟悉AS2,但this pagecontentPath属性必须是

  

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


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