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

To test this script, place an ARAvatarTrigger in your level (ARAvatarTrigger ScriptCommand Property should be: EntityNamed("HudExample1"):DisplayHud();); be sure to register this HudExample entity and place it in the level as well.

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.

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 Flash file. 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