在 Flex 中使用 Flash 组件 SWC 文件 [英] Using Flash Component SWC file in Flex

查看:32
本文介绍了在 Flex 中使用 Flash 组件 SWC 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 Flex 3 的 SWC 文件访问自定义 UIComponent.该组件在 Flash CS3 中工作正常,但在 Flex 中使用它会在 draw() 中出现一个奇怪的错误.

I am accessing custom UIComponent via SWC file from Flex 3. This component works OK in Flash CS3, but using it from Flex gives A weird error in draw().

我在 Sprite(带有 addchild)及其 LIB 路径中添加了 swc 组件.

I have added swc component inside Sprite (with addchild) and its in LIB path.

类型错误:错误 #1010:术语未定义且没有属性.

TypeError: Error #1010: A term is undefined and has no properties.

at com.xxxx.highscores::HighScores/draw()

at fl.core::UIComponent/callLaterDispatcher()

这是这个 UI 组件的 draw() 函数:

Here is the draw() function of this UI Component:

覆盖受保护的函数 draw():void {isInitializing = false;

override protected function draw():void { isInitializing = false;

     page.Text.x = width / 2;
     page.Text.y = height / 2;

     drawBackground();

}

推荐答案

只有那个代码,它必须要么是 page,要么是 page.Text 为空.

With only that code, it must be either page, or page.Text, is null.

顾名思义,我猜页面是您用 AS 创建的 Flash 库对象?如果是这样,我猜之前的错误是在它被创建并被播放器吞没之前触发的(如果调试器尚未附加,或者加载共享库出现问题,可能会发生).在将新显示对象添加到显示列表之前,不会为新显示对象设置舞台"很常见.

这是组件中的一个错误:draw() 总是在页面上使用 highScoresModuleText 属性:它仅在页面是 HighScoresTextPage 时设置,而不是任何其他页面,例如:HighScoresTablePageshowHighsSores() 将其设置为.这可能在 Flash 中有效,因为对象在舞台上,或者至少在 showHighScores() 被调用之前被创建,所以 draw() 首先被调用,并且由于组件不会失效,不会被调用.

It's a bug in the component: draw() always uses the highScoresModuleText property on page: which is only set when the page is a HighScoresTextPage, and not any of the other pages, eg: HighScoresTablePage, which showHighsSores() sets it to. This works in Flash presumably because the object is on the stage, or at least gets created before showHighScores() is called, so draw() gets called first, and since the component does not invalidate, is not called after.

在这种情况下正确的方法是让 show*() 只设置一些属性,然后 invalidate()draw()> 稍后弄清楚,但快速解决方法是在 draw() 中的违规行周围添加if (page.highScoresModuleText)".一个更快的解决方法是尽早创建和addChild()组件(如启动),然后调用showHighScores().

The correct method in this case is to have show*() just set some properties, then invalidate() to have draw() figure it out later, but a quick fix is to just add 'if (page.highScoresModuleText)' around the offending lines in draw(). An even quicker fix is to create and addChild() the component early (like startup), and call showHighScores() much later.

这对我有用:

package
{
    import flash.display.Sprite;
    import com.novelgames.flashgames.highscores.HighScores;
    import flash.events.MouseEvent;

    public class As3_scratch extends Sprite
    {
        private var highscore : HighScores;

        public function As3_scratch()
        {
            highscore = new HighScores();
            addChild(highscore);
            stage.addEventListener(MouseEvent.CLICK, onClick);
        }

        private function onClick(event : MouseEvent) : void
        {
            highscore.showEnterHighScore(50);
        }
    }
}

这篇关于在 Flex 中使用 Flash 组件 SWC 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆