Using Flash Component SWC File in Flex

I access the custom UIComponent through a SWC file from Flex 3. This component works fine in Flash CS3, but using it from Flex gives a strange error in draw ().

I added the swc component inside Sprite (with addchild) and its in the lib path.

TypeError: Error # 1010: The 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 user interface component:

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

  page.Text.x = width / 2; page.Text.y = height / 2; drawBackground(); 

}

0
flex flash components
source share
2 answers

Only with this code should it be either a page or page.Text, null.

Going by name, I would suggest that the page is a Flash library object that you create using AS? If this is the case, I would suggest that the previous error is triggered before it is created and launched by the player (it can happen if the debugger is not already connected, or there are problems loading shared libraries). "stage" is not set for a new display object until it is added to the display list. Usual

EDIT: error in component: draw() always uses the highScoresModuleText property on the page: it is set only when the page is HighScoresTextPage , and not any other page, for example: HighScoresTablePage , which sets showHighsSores() . This works in Flash, presumably because the object is on stage, or at least created before showHighScores() is showHighScores() , therefore draw() is called first, and since the component does not invalidate, it is not called after.

The correct method in this case is to show*() just set some properties and then invalidate() so draw() defines it later, but a quick solution is to simply add ' if (page.highScoresModuleText) 'around offensive lines in draw() . An even quicker fix is ​​to create the addChild() component earlier (for example, launch) 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); } } } 
+3
source share

Here is the link to download this (free) source flash component http://www.novelgames.com/otherdownloads/highscores/

so I call it from the Flex project:

  addChild(highscore); highscore.showHighScores(); 

-> crashes shortly afterwards

0
source share

All Articles