Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Current »

How Do We Expose Scoring?

Now that we have explored how to expose both vector and bitmap images, the following chapters will look at how you can use visual scripting to call a function in your game that will change a text label in Flash.

Considering how you will learn to expose a function that provides the dynamic textbox a value to print out, you will learn a valuable aspect of UI and how easy it is to show your score or game time on screen for a more engaging gameplay experience.

Exposing a Function for Dynamic Text

Scaleform 3

  1. Draw a Dynamic Textbox inside of the Flash canvas and type "Score: 0." in the box.

    Dynamic Textbox

  2. Name the instance "lblScore" and click the Selectable Button to disable selecting the text if the cursor is enabled. You can also set the Paragraph option to left-justified.

    lblScore

  3. Access the Actions Window by either pressing F9 or going to Window → Actions in the menu.

    Window → Actions

  4. Considering how this is the most basic form of ActionScript we can enter, we will house the script in the default layer as is (Scene 1 → Layer 1: Frame 1), and enter the following code to expose our function and allow Scaleform to call it:

    uiQuickStart.fla
    function updateScore(value:Number)
    {
        lblScore.text = "Score: " + value;
    }


    House the script in the default layer

  5. Now that you have defined your function, you can compile your GFx file through the exporter as explained in Chapter 2 - Flash and Gfx, then enter the following adjustments to your UI Elements XML file to expose the function to visual scripting:

    uiQuickStart.xml
    		<functions>
    			<function name="UpdateScore" funcname="updateScore" desc="Updates our score">
    			<param name="value" desc="New score" type="int" />
    			</function>
    		</functions>


    Exposing the function to visual scripting

Scaleform 4

  1. Draw a Dynamic Textbox inside of the Flash canvas and type "Score: 0." in the box.

    Dynamic Textbox

  2. Name the instance "lblScore" and make sure a suitable color and size is chosen.

    lblscore

  3. Access the Actions Window by either pressing F9 or going to Window → Actions in the menu.

    Window → Actions

  4. Considering how this is the most basic form of ActionScript we can enter, we will house the script on the default layer as is (Scene 1, Layer 1, Frame 1), and enter the following code to expose our function and allow Scaleform to call it:


    House the script in the default layer

    uiQuickStart.fla
    function updateScore(value:Number)
    {
        lblScore.text = "Score: " + value;
    }
  5. Now that we have defined our function, we can compile our GFx file through the exporter as explained in Chapter 2 - Flash and Gfx,, then enter the following adjustments to our UI Elements XML file to expose the function to visual scripting:

    uiQuickStart.xml
    		<functions>
    			<function name="UpdateScore" funcname="updateScore" desc="Updates our score">
    			<param name="value" desc="New score" type="int" />
    			</function>
    		</functions>


    Exposing the function to visual scripting

On This Page

  • No labels