Action Script 3 新加载程序

发布于 2024-12-17 08:50:34 字数 512 浏览 3 评论 0原文

我正在重新审视在 Action Script 2.0 中创建的简单图片查看器的一些代码,现在在 AS3 中承担相同的任务。目前我很清楚命令 .loadMovie 已不再使用。经过多次尝试寻找解决方案后,我却一无所获。

目前,我在舞台上有一个影片剪辑符号(target_mc),当我将鼠标悬停在按钮上时,我想从外部文件加载 jpeg。任何人都可以举例说明如何使用“新加载”变量来实现这一点。在 AS2 版本中,我也在按钮代码中使用(在发布时)。

Training_btn 是按钮实例。

请参阅下面的我的代码示例:

training_btn.addEventListener(MouseEvent.CLICK, imageOver);
function imageOver(evt:MouseEvent) {    
    this.target_mc.loadMovie("galleryimage/p_traininglink.jpg")
}

任何想法都会非常有帮助。

韦恩

I was revisiting some code for a simple picture viewer that I created in Action Script 2.0 now taking on the same task in AS3. At present i'm well aware that the command .loadMovie is no longer used. After numerous attempts to find a solution I have come up dry.

At the moment I have a movie clip symbol(target_mc) on the stage that I want to load jpegs from a external file when I mouseOver a button. Can any one give a example of how this should be approached using the "new load" variable.In the AS2 version i also used (on release) in the button code.

training_btn is the button instance.

Please see an example of my code below:

training_btn.addEventListener(MouseEvent.CLICK, imageOver);
function imageOver(evt:MouseEvent) {    
    this.target_mc.loadMovie("galleryimage/p_traininglink.jpg")
}

Any ideas would be very helpful.

Wayne

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

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

发布评论

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

评论(4

旧夏天 2024-12-24 08:50:34

Here at the Republic of Code 是一个关于如何使用 as3 中的加载器类

Here at the Republic of Code is an excellent step-by-step tutorial on how to work with the loader class in as3

贱贱哒 2024-12-24 08:50:34

是的

 training_btn.addEventListener (MouseEvent.MOUSE_UP, onMouseUp);

 function onMouseUp (evt:MouseEvent):void {
    var my_loader:Loader = new Loader();
    my_loader.load(new URLRequest("myPhoto.jpg"));
    target_mc.addChild(my_loader);

 }

Yeap

 training_btn.addEventListener (MouseEvent.MOUSE_UP, onMouseUp);

 function onMouseUp (evt:MouseEvent):void {
    var my_loader:Loader = new Loader();
    my_loader.load(new URLRequest("myPhoto.jpg"));
    target_mc.addChild(my_loader);

 }
陌伤浅笑 2024-12-24 08:50:34

因此,基本上,laoder 的整个结构在 AS 2 和 3 之间发生了变化。

现在您需要创建一个不同的对象来加载内容。

var loader:Loader = new Loader();

您可以做两件事:

  1. 添加事件监听器并触发加载
  2. 触发加载并将加载器添加到舞台

这两种风格之间的区别很大,第一个将添加监听器并等待加载完成,然后它将调用您在侦听器中定义的方法来执行任何进一步的指令。
第二个开始加载内容并将加载器添加到显示列表中,以便在加载内容时自动显示。

1.

// add the listener
laoder.contentLoaderInfo.addEventListener( Event.Complete, onLoadComplete );
// trigger the load (remember: the url is alwais a URLRequest object)
loader.load( new URLRequest("path_to_file") );
// additional var for storing the content (only the content, without the loader)
var content:Bitmap;

function onLoadComplete( e:Event ):void{
content = e.target.content as Bitmap;
// you could use also:
// content = loader.content as Bitmap;

// you can do some modifications before displaying the content

// and finally add it to the display list
this.target_mc.addChild( content );
}

2)

// trigger the load (remember: the url is alwais a URLRequest object)
loader.load( new URLRequest("path_to_file") );

this.target_mc.addChild( loader );

这两种方法都是正确的,但我更喜欢使用第一种方法,因为它给你更多的控制权。您还可以通过监听ProgressEvent.PROGRESS来检查加载进度。

  • 链接:加载器文档
  • 链接:< a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html" rel="nofollow">URLRequest 文档

希望有帮助。在谷歌中搜索有关加载外部数据的更多信息,有很多关于这方面的资源。

So, basically the whole structure of the laoder has change between AS 2 and 3.

Now you need to create a different object that loads the content.

var loader:Loader = new Loader();

Than you can do two things:

  1. Add event listener and than trigger the load
  2. Trigger the load and add the loader to the stage

The difference between these two style is big, the first one will add a listener and wait for the load to complete and after that it will call a method you define in the listener to do any further instuctions.
The second one starts loading the content and adds the loader to the display list so that when the content is loaded it automatically displays.

1.

// add the listener
laoder.contentLoaderInfo.addEventListener( Event.Complete, onLoadComplete );
// trigger the load (remember: the url is alwais a URLRequest object)
loader.load( new URLRequest("path_to_file") );
// additional var for storing the content (only the content, without the loader)
var content:Bitmap;

function onLoadComplete( e:Event ):void{
content = e.target.content as Bitmap;
// you could use also:
// content = loader.content as Bitmap;

// you can do some modifications before displaying the content

// and finally add it to the display list
this.target_mc.addChild( content );
}

2)

// trigger the load (remember: the url is alwais a URLRequest object)
loader.load( new URLRequest("path_to_file") );

this.target_mc.addChild( loader );

The two ways are correct but I prefer using the first one cause it gives you more controll. You can also check out the progress of loading by listening to the ProgressEvent.PROGRESS.

Hope it helps. Search in google for more info about loading external data, there's a lot of resource about that.

一页 2024-12-24 08:50:34

最好创建一个可以处理所有这些的类,但是为了回答您的问题,您的代码将类似于:

var outLoader:Loader = new Loader();
outLoader.load(new URLRequest("outImage.jpg"));

var overLoader:Loader = new Loader();
overLoader.load(new URLRequest("overImage.jpg"));
overLoader.visible = false;

var training_btn:Sprite = new Sprite();
training_btn.addChild(outLoader);
training_btn.addChild(overLoader);
training_btn.buttonMode = true;
training_btn.mouseChildren = false;
training_btn.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
training_btn.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
addChild(training_btn);

function rollOverHandler(e:MouseEvent):void {
    overLoader.visible = true;
}

function rollOutHandler(e:MouseEvent):void {
    overLoader.visible = false;
}

It would probably best to create a Class that would handle all of this, but to answer your question, your code would look something like:

var outLoader:Loader = new Loader();
outLoader.load(new URLRequest("outImage.jpg"));

var overLoader:Loader = new Loader();
overLoader.load(new URLRequest("overImage.jpg"));
overLoader.visible = false;

var training_btn:Sprite = new Sprite();
training_btn.addChild(outLoader);
training_btn.addChild(overLoader);
training_btn.buttonMode = true;
training_btn.mouseChildren = false;
training_btn.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
training_btn.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
addChild(training_btn);

function rollOverHandler(e:MouseEvent):void {
    overLoader.visible = true;
}

function rollOutHandler(e:MouseEvent):void {
    overLoader.visible = false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文