Basic HUD Example

From Blue Mars Developer Guidebook

Jump to: navigation, search
There are security restrictions on this article

Contents

This basic HUD example illustrates:

  1. Loading, showing, hiding and setting ActionScript variables in a Flash movie with HUD functions
  2. Instructions for both modal and non-modal movies to receive mouse events
  3. Listening for and handling fscommands
  4. Using the fscommand function in ActionScript


Using the HUD Lua API

First, create your HudExample entity by following the two steps below, or unzipping File:Common.zip to your Common directory (adjusting the path in the .ent to match your company code).

  1. Copy and save the HudExample script (below) in your Common/Scripts/Entities directory and name it HudExample.lua
  2. Register the entity in your Common/Entities directory by creating a file named HudExample.ent which points to your script, similar to the following, replacing SAMPLE with your company code:
<Entity Name="HudExample" Script="Levels/SAMPLE/Common/Scripts/Entities/HudExample.lua"/>
Testing

To test this script, open your level in the City Editor and

  1. Place your HudExample entity in your level by dragging it in from the Entity Browser in the RollupBar.
  2. Place an ARAvatarTrigger in your level and enter the following in the ARAvatarTrigger ScriptCommand Property: EntityNamed("HudExample1"):DisplayHud();
  3. Enter Preview Mode (BlueMars>Switch to Preview Mode) and navigate into the avatar trigger

What to expect: when the avatar enters the trigger, you'll see the Flash movie come up in the Display state. Upon clicking Btn1 or Btn2, a debug message reports which was clicked, the movie is cleaned up and hidden, and the Finish state is entered.

Upon walking into the ARAvatarTrigger the popup dialog is displayed; the button choice is printed in a debug message


HudExample Lua script
HudExample = 
{
  States = 
  {
    "Display",
    "Finish",
  },

  Hud = {
    popup = "libs/ui/ar/common/confirm_popup.swf",
  },
}

function HudExample:DisplayHud()
  HUD.LoadFlash(self.Hud.popup);
  self:GotoState("Display");
end

function HudExample:OnReset()
  self:GotoState("Finish");
end

HudExample.Display = 
{
  OnBeginState = function(self) 
    HUD.Modal(self.Hud.popup); 
    --note: if the movie does not need to be modal (the only flash element to receive mouse input events) 
    --      then HandleFlashEvents should be used to receive mouse events: HUD.HandleFlashEvents(self.Hud.popup);
    --also, if the movie is not modal but it should block mouse clicks from, say, also being input to the navigation system, 
    --      then MaskFlashEvents should be used: HUD.MaskFlashEvents(self.Hud.popup, eFAF_MaskVisibleShape);  
    HUD.AddFSCommandListener(self.Hud.popup, self.id); --this causes the movie to send fscommands to this entity script
    HUD.SetFlashVariable(self.Hud.popup, "confirmMessage", "This is a test dialog"); 
    HUD.SetFlashVariable(self.Hud.popup, "btnText_left", "Btn1"); 
    HUD.SetFlashVariable(self.Hud.popup, "btnText_right", "Btn2");  
    HUD.ShowFlash(self.Hud.popup);
  end,
  OnFSCommand = function(self,command,arg)
    if (command == "Confirm:BtnLeft") then
      ARDebugMessage("Clicked Btn1");
      self:GotoState("Finish");
    elseif (command == "Confirm:BtnRight") then
      ARDebugMessage("Clicked Btn2");
      self:GotoState("Finish");
    elseif (command == "Confirm:CloseBtn") then
      self:GotoState("Finish");
    end
  end,
  OnEndState = function(self)
    HUD.Modeless();
    HUD.HideFlash(self.Hud.popup);
    HUD.SetFlashVariable(self.Hud.popup,"confirmMessage",""); 
    HUD.SetFlashVariable(self.Hud.popup,"btnText_left",""); 
    HUD.SetFlashVariable(self.Hud.popup,"btnText_right","");
    HUD.RemoveFSCommandListener(self.Hud.popup,self.id);
  end,
}

HudExample.Finish = {}


ActionScript

For reference, here's the ActionScript (2.0) from the confirm_popup.swf Flash file which is included in the SDK. The vars are the names of the Dynamic Text fields (confirmMessage in the center of the popup, and btnText_left and _right over the buttons) which are Embedded with the Uppercase, Lowercase, Numerals and Punctuation character sets. The fscommand functions communicate with the entity script upon releasing the respective buttons.

//ActionScript from the Flash file
var confirmMessage;
var btnText_left;
var btnText_right;

leftBtn.onRelease = function()
{
   fscommand("Confirm:BtnLeft", "");
}

rightBtn.onRelease = function()
{
   fscommand("Confirm:BtnRight", "");
}

closeBtn.onRelease = function()
{
   fscommand("Confirm:CloseBtn", "");
}

Author: Magnolia @ AR

See HUD for further details

Back to the Script Center

Problems with this wiki page? Contact us either by: Support Email or Support Ticket System

Blue Mars Guidebook Privacy Policy
Blue Mars Guidebook Community Guidelines

Personal tools