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

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

问题描述

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

我在Sprite(带有addchild)和LIB路径中添加了swc组件。



TypeError:错误#1010:一个术语是未定义的,没有任何属性。

  at com.xxxx.highscores :: HighScores / draw()
$ b $ flcore :: UIComponent / callLaterDispatcher()
$ b $ p这里是这个UI组件的draw()函数:

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

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

drawBackground();

}

解决方案只有这个代码,它必须是页面,或page.Text,为空。



按照名称,我猜页面是用AS创建的Flash库对象?如果是这样的话,我猜想以前的错误是在它被创建之前触发的,并且被播放器所吞噬(如果调试器尚未连接,或者加载共享库的问题可能会发生)。编辑:这是组件中的一个错误:<$>
$ b 编辑:这是组件中的错误: draw()总是使用页面上的 highScoresModuleText 属性,该属性仅在页面为 HighScoresTextPage ,而不是任何其他页面,例如: HighScoresTablePage ,其中 showHighsSores()将其设置为。这在Flash中可行,大概是因为对象在舞台上,或者至少在调用 showHighScores()之前创建,所以 draw() code>首先被调用,并且由于组件不会失效,所以不会被调用。



在这种情况下,正确的方法是将 show *()只是设置一些属性,然后 invalidate()具有 draw()稍后解决,但是一个快速的解决方法是在中的违规行周围添加'(code> if(page.highScoresModuleText)') )。更快的解决方法是在组件的早期(比如启动)创建 addChild(),并调用 showHighScores()

这对我有用:

  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);
}
}
}


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().

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

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

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

at fl.core::UIComponent/callLaterDispatcher()

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

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

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

     drawBackground();

}

解决方案

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

Going by the names, I would guess page is a Flash library object you create with AS? If so, I would guess a previous error is firing before it is created and being swollowed by the player (can happen if the debugger has not attached yet, or problems with loading shared librarys). 'stage' not being set for new display object until it's added to the display list is common.

EDIT: 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.

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.

This works for me:

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天全站免登陆