AS2:检查MovieClip是否渲染了任何图形
我正在使用 MediaMind 使用 ActionScript 2 制作 SmartVersioning 广告(发布商不允许使用 AS3)。
跳过它的实现方式 - 基本上我拥有的是主时间轴上的MovieClip集合,其中包含可交换图像(通过智能版本控制服务)。仅当对象位于主时间轴上时,您才能将其定义为智能版本控制对象。
我正在做的是使用 BitmapData 将主时间轴上的资源用作整个动画中的图形源。
应该很简单:
import flash.display.BitmapData;
var bmd:BitmapData = new BitmapData(143, 230, true, 0);
bmd.draw(_root.person1);
attachBitmap(bmd, getNextHighestDepth());
但是,加载智能版本控制资源(即整个动画所需的图像)会出现延迟 - 因此,如果资源未及时加载,这可能会导致上述代码失败。
然后我继续将上面的代码修改为:
import flash.display.BitmapData;
var bmd:BitmapData = new BitmapData(143, 230, true, 0);
onEnterFrame = function():Void
{
bmd.draw(_root.person1);
}
attachBitmap(bmd, getNextHighestDepth());
可以工作,但有明显的问题并且编码非常糟糕。那么,有没有办法检查是否有任何图形已绘制到该代码运行的 MovieClip 中?像这样的东西:
onEnterFrame = function():Void
{
if(<hasNoGraphicsYet>)
bmd.draw(_root.person1);
else
delete(onEnterFrame);
}
I'm working on a SmartVersioning ad using MediaMind using ActionScript 2 (the publisher doesn't allow AS3).
Skipping over how it's implemented - basically what I have is a collection of MovieClips on the main timeline that contain a swappable image (through the Smart Versioning service). You can only define objects as Smart Versioning objects if they are on the main timeline.
What I'm doing with this is using BitmapData to use the assets on the main timeline as a source for the graphics throughout the animation.
Should be as easy as:
import flash.display.BitmapData;
var bmd:BitmapData = new BitmapData(143, 230, true, 0);
bmd.draw(_root.person1);
attachBitmap(bmd, getNextHighestDepth());
However there's a delay in loading Smart Versioning assets (ie the images needed throughout the animation) - so this can cause the above code to fail if the asset hasn't loaded in time.
I then went on to amend my above code to:
import flash.display.BitmapData;
var bmd:BitmapData = new BitmapData(143, 230, true, 0);
onEnterFrame = function():Void
{
bmd.draw(_root.person1);
}
attachBitmap(bmd, getNextHighestDepth());
Works, but has obvious problems and is pretty poor coding. So, is there a way to do a check to see if any graphics have been drawn into the MovieClip this code is run within? Something like:
onEnterFrame = function():Void
{
if(<hasNoGraphicsYet>)
bmd.draw(_root.person1);
else
delete(onEnterFrame);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是对的,使用这些 EnterFrame 检查是糟糕的编码。为什么不使用 SmartVersioning 组件中的 COMPLETE 事件来确定资产 XML 的加载时间?
来自 mediamind 的 C&P:
You're right that using those enterFrame checks is bad coding. Why not use the COMPLETE event from the SmartVersioning component to determine when your asset XML is loaded?
C&P from mediamind:
您可以检查
MovieClip
的宽度
和高度
,如果上面没有绘制任何内容,它们应该是0
。You could check the
width
andheight
of theMovieClip
They should be0
if nothing is drawn on it.