如何使用新的 movieClip 作为类或在不引用其类的情况下复制它?
我正在用 2 个相同的 BG movieClip(B1 和 B2)制作循环背景。这两个是同一个班级的“新”人。
var B1:MovieClip = new BG();
var B2:MovieClip = new BG();
但是因为这个BG类图片是从网上加载的,而且图片比较大。当我使用 ProgressEvent 解决其加载问题时。图片确实加载了2次。无论如何,我是否可以基于 B1 创建 B2 而无需再次使用 new BG() ?因为它肯定会创建一个新的BG,里面有Loader代码。 谢谢您的帮助^^
对于BG类代码:
var URLvar:URLRequest;
var BGLoader : Loader = new Loader( );
URLvar = new URLRequest( "somewherelink.jpg" );
BGLoader.load(URLvar);
this.addChild(BGLoader);
有什么方法可以设置如果B1完全加载,我将其复制到B2中吗?或任何其他方式来实现相同的目标?
import flash.display.*;
import flash.utils.*;
var obj:Class = getDefinitionByName(“bluebox”) as Class;
addChild(MovieClip(new obj()));
我在动态创建类中找到了这个,但我不知道如何使用T_T,你能给我解释一下吗?我可以在这种情况下使用它吗? 谢谢您的宝贵时间^^
I am doing a looping background with 2 identical BG movieClip (B1 and B2). Those 2 are "new" by the same class.
var B1:MovieClip = new BG();
var B2:MovieClip = new BG();
But because this BG class picture is loader from the internet and the picture is rather big. When I addressed its loading by using progressEvent. The picture is really loaded 2 times. Is there anyway I create B2 based on B1 without using new BG() again? Since it definitely makes a new BG with Loader code inside.
Thank you for your help ^^
For BG class code:
var URLvar:URLRequest;
var BGLoader : Loader = new Loader( );
URLvar = new URLRequest( "somewherelink.jpg" );
BGLoader.load(URLvar);
this.addChild(BGLoader);
is there any way that I set if the B1 is completely loaded, I copy it into B2? or any other way to achieve the same goal?
import flash.display.*;
import flash.utils.*;
var obj:Class = getDefinitionByName(“bluebox”) as Class;
addChild(MovieClip(new obj()));
I found this one in a dynamically Create Class, but I dunno how to use T_T, can you explain it to me and can I use it in this situation?
Thank you for your time ^^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于这个答案,我假设您总是希望拥有相同的图像两次,而不是两个不同的图像。您遇到的问题是您的 BG 类完全在内部完成加载和附加。我的首选方法是加载一次,然后创建加载内容的实例。
对于第二个问题... getDefinitionByName 返回一个代表命名类的对象,而不是它的实例。因此,在您的示例中,它正在获取“bluebox”类的定义,该类位于应用程序源的根目录中(而不是在文件夹中)。
获得该类对象后,您可以使用 new 关键字创建它的实例。就我而言,最大的缺点是您不导入该类,因此在您的示例中 obj 被转换为 MovieClip。这使得代码编辑器的功能(例如代码完成和错误突出显示)无法正常工作,因为“bluebox”的属性和方法没有公开。
我通常只使用它来创建将在其他地方定义其类的对象,例如在运行时加载的 XML 文件中。
For this answer I'm going to assume that you are always going to want to have the same image twice, rather than two different ones. The problem you have is that your BG class does the load and the attach completely internally. My preferred approach would be to load once, and then create to instances of the loaded content.
For your second question...
getDefinitionByName
returns you an object that represents a named class, rather than an instance of it. So in your example, it is getting a definition for the class 'bluebox', which is in the root of your application source (not in a folder).Once you have that class object you can create instances of it with the
new
keyword. The big disadvantage of this as far as I'm concerned is that you don't import the class, hence in your exampleobj
is cast as a MovieClip. That makes features of code editors like code completion and error highlighting to not work correctly because the properties and methods of 'bluebox' are not exposed.I usually only use this for creating objects that will have their classes defined elsewhere, in an XML file that is loaded at runtime for example.
如果两个浏览器的 URLRequest URL 相同,则浏览器将在第二次提供缓存版本。该请求向浏览器发出两次,但仅向服务器发出一次。您可以使用 httpfox、charles 或 fiddler 等 http 嗅探器来验证请求。
If the URLRequest URL is the same for both the browser will serve up a cached version the second time around. The request is made to the browser twice, but only once to the server. You can use an http sniffer like httpfox, charles or fiddler to validate the requests.