Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
354 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...