Scaleform Pitfall: Local vs. Global

The last few days I’ve been busy converting my Bulletstorm Point System to Scaleform, and one of the things I’ve had to do is dynamically spawn instances of a symbol, set their position/scale/alpha/etc., and attach them to the HUD.

For the longest time I tackled one major problem: the dynamic point messages that were supposed to pop up weren’t popping up. I tried everything I could, searched all the forums, checked my code a million times, and I still couldn’t figure out why they seemed to be completely invisible. I was about to give up.

Then it dawned on me. When you dynamically spawn an instance of a symbol and set its position, the position is set relative to the symbol’s local origin (that little hollow circle in Flash), NOT the global stage position (with 0,0 in the top left corner). This poses a major problem if the original instance is off the screen because when the new position is set, it will be set relative to this off-screen location and will still be off the screen (in other words, completely invisible).

Sticking dynamic objects out of the frame is a common Scaleform practice because you don’t want to see them at runtime, before they can be initialized. For example, in the UDK menus the cursor is off the screen to the left, safely out of view. I thought it would be okay to just dump my Bulletstorm message symbol off the frame, but I was wrong.

What you actually want to do is set the symbol’s location to (0,0), so that the little circle is directly over the scene’s top left corner. If parts of the symbol still stick into view, just set its visibility to false; you can always change it later once you set the correct position in UnrealScript. Now with the idea of local/global settings in mind, hopefully you can avoid this nasty Scaleform pitfall.

Advertisements

6 thoughts on “Scaleform Pitfall: Local vs. Global

  1. It’s really a Flash ‘feature’ that causes all kinds of nightmares if you are not used to it.

    Every MovieClip in flash has it’s own timeline and registration point, but it’s coords are relative to it’s parent.

    Say you have a fullscreen movie called ‘container’ and you have a MovieClip called ‘score’ in the library that you want to attach and your ‘score’ movieClip has a textField called ‘myScoreText’ at 10,10

    If you add score:

    newScore = container.attachMovie(“score”, “score_01”, container.getNextHighestDepth());

    Then move it over to the right 200 pixels
    newScore._x = 200;

    The textField will now be 210 pixels to the right but when you get the x position of the textifleld

    trace(newScore.myScoreText._x);
    It will say 10 because it’s relative to score not container.

    You probably already know this by now but here’s a video on nesting symbols
    http://tv.adobe.com/watch/learn-flash-professional-cs5/gs05-nesting-symbols/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s