与装载机决斗时两次装载相同的东西时遇到麻烦
我有一个执行加载外部 jpg 工作的背景符号,以及一个在屏幕上连续循环 2 个背景的引擎 as3。然而,只有一个背景可以加载文件,尽管它们是来自同一符号的“新”背景。为了测试这个 urr... 现象,我交换了 2 个背景的“新”代码的顺序,然后顶部的那个将完美加载 jpg 文件,另一个将保持空白。 以前有人遇到过这个问题吗?或者知道如何解决?请教我。这种外部负载从一开始就让我感到非常痛苦。
对于代码:(因为它非常非常基本,所以我想我可以忽略它;对于给您带来的不便表示歉意)
背景代码
var URLvar:URLRequest;
var fBGLoader : Loader = new Loader( );
URLvar = new URLRequest( "background collection/fyrise/fyriseFront.png" );
fBGLoader.load(URLvar);
this.addChild(fBGLoader);
引擎代码,
private var B1:fBG;
private var B2:fBG;
private var Container= new MovieClip();
BLen=2500;
B2=new fBG();
B1=new fBG();
B1.x=0;
B1.y=0;
B2.x=B1.x-BLen;
B2.y= B1.y;
Container.addChild(B1);
Container.addChild(B2);
stage.addChild(Container);
如您所见,我将 B2 = new fBG() 放在 B1=new fBG( ),那么我可以看到 B2 但看不到 B1,如果我交换顺序,我可以看到 B1 但看不到 B2。这就是问题所在!
I have a background symbol that does the loading external jpg job, and a engine as3 that loops 2 backgrounds continuously on the screen. However, only one background can load file although they "new" from the same symbol. To test this urr... phenomenon, I exchange the order of "new" code of 2 backgrounds, then whichever on top will perfectly load the jpg file and the other will remain blank.
has anyone faced this problem before? or knowing how to solve it? plz teach me. this external loading is really painful to me from the beginning.
For the code: (because it is very very basic so I think I could neglect it; sorry for the inconvenience)
Background code
var URLvar:URLRequest;
var fBGLoader : Loader = new Loader( );
URLvar = new URLRequest( "background collection/fyrise/fyriseFront.png" );
fBGLoader.load(URLvar);
this.addChild(fBGLoader);
Engine code
private var B1:fBG;
private var B2:fBG;
private var Container= new MovieClip();
BLen=2500;
B2=new fBG();
B1=new fBG();
B1.x=0;
B1.y=0;
B2.x=B1.x-BLen;
B2.y= B1.y;
Container.addChild(B1);
Container.addChild(B2);
stage.addChild(Container);
so as you can see, I put the B2 = new fBG() prior to B1=new fBG(), then I can see B2 but not B1 and if I exchange the order, I can see B1 but not B2. That's the problem!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您加载图像两次还是只加载一次?如果您加载图像一次并将其用于两个 fBG 对象,您会遇到这个问题,因为 Bitmap 对象只能有一个父对象(最后一个 addChild(fBGLoader) 是唯一有效的,第一个对象将被后一个对象取消)。
要解决此问题,您需要确保两个 fBG 对象都有自己的 Bitmap 实例(但是它们可以共享相同的 BitmapData)。因此,无论您在做什么:
请改为这样做:
这将确保每个 fBG 对象都有自己的一组坐标和信息来显示背景图像。
Are you loading the image twice or just once? If you load the image once and use it for both fBG objects you would get that problem since Bitmap objects can only have a single parent (the last addChild(fBGLoader) is the only one working, the first one will be cancelled by the later one).
To fix this, you need to make sure that both fBG objects have their own Bitmap instance (they can however share the same BitmapData). So wherever you are doing :
Do this instead :
This will make sure that each fBG object has it's own set of coordinates and information to display the background image.
“背景代码”是
fBG
类吗?如果是这样,该代码是否在构造函数中运行?如果是这样,我认为你的解决方案应该有效。但如果不了解更多背景,就很难下结论。您应该能够加载同一个图像两次并且不会出现问题。所以我的猜测是你的问题围绕着你如何设置你的类(例如我之前提到的上下文)。我猜您还遇到了一些其他问题,但您提供的代码中未显示这些问题。
顺便说一句,如果您只想要两个相同的图像,那么您实际上并不需要两个单独的加载器。您只需加载图像一次,然后使用位图类创建加载器内容的副本。
哦,再看一遍,你的说法:
行不通。你需要类似的东西:
Is the "background code" the
fBG
class? And if so, is that code being run in the constructor? If so, I think your solution should work. But it's hard to say without seeing a bit more context.You should be able to load the same image twice and not have a problem. So my guess is that your issue is revolving around how you've set up your classes (e.g. the context I mentioned before). I'm guessing you've got some other issue there that isn't shown in the code you've provided.
As an aside, you don't really need two separate loaders if you just want two of the same image. You could just load the image once and then use the Bitmap classes to create a copy of the Loader's content.
Oh, and on second look, your statement:
won't work. You need something like:
我在 Wonderfl 上整理了一个小例子: http://wonderfl.net/c/1dze
我只是尝试加载相同的图像两次 - 并且它有效。这是代码:
问题必须出在代码的其他地方。
也许首先尝试更改影片剪辑的位置,看看两者是否都已加载 - 就像我在上面的代码中所做的那样。
编辑
你也可以将其放入两个类中,如下所示:
然后
i put together a small example over at wonderfl: http://wonderfl.net/c/1dze
i just try and load the same image twice - and it works. here is the code:
the problem has to be somewhere else in your code.
maybe try changing the position of the movieclips first to see if both are loaded - like i did in the code above.
edit
you could also put this into two classes like so:
and then
如果我正确地阅读了您的代码,您的实例之一位于屏幕上的 -2500 px x 坐标。是否有可能图形正在加载,但由于它距离视口左侧太远,所以您看不到它?
另外,我同意其他一些海报的观点,即最好只加载文件一次,然后复制它。您可以在此处找到有关执行此操作的技术的更多信息:http://www.adobe .com/devnet/flash/articles/blitting_mc.html。
HTH;
艾米
One of your instances is at -2500 px x coordinate on the screen, if I read your code correctly. Is it possible that the graphic is loading, but because it is so far to the left of the viewport, you can't see it?
Also, I agree with some of the other posters that it is probably better to only load the file once, then duplicate it. You can find out more about techniques for doing this here: http://www.adobe.com/devnet/flash/articles/blitting_mc.html.
HTH;
Amy