views:

31

answers:

0

What would be the best way to set up a navigation system that acts like a TV remote control using Flash and AS3? I'm building an interactive demo that will simulate playing content and voting on your TV, using navigation similiar to say "Direct TV's remote control". Navigating each page through your remote with assigned keyboard commands.

The remote arrow keys will move your selection up, down, right, left, etc...

How would you approach this, before I get to deep I want to know if there's a better approach. Am I on track or would you do it differently? I was thinking of making each page an array and its nested movieclips in there own array -- will be used to navigate through them. But as I start to add more pages, the code is getting really long and confusing. Here is some of what I have.... The ControllerLogic AS file contains the order of the pages as

 /* The ControllerLogic.as file contains an array of the order of the pages. Methods are stored for global access */
public static var myVoteSequence:Array = new Array("select", 
             "question", 
             "poll_result",
             "phone",
             "thanx",
             "rating");


package
{
 import flash.display.MovieClip;
 import flash.events.MouseEvent;
 import flash.events.Event;
 import flash.display.SimpleButton;
 import ControllerLogic;

public class RemoteControl extends MovieClip
 {
private var _questionArray:Array;
private var _ratingArray:Array;
private var _votingArray:Array;
private var _phoneArray:Array;
private var _count:int;
private var _pg:int;
private var _p_result:Boolean;
private var _intervalCount:int;
private var _myVoteSequence:Array;
private var _videoPlayed:Boolean;
private var _demoType:String;
private var _demoHasBeenRest:Boolean;
private var _demoToggle:Boolean;
public function RemoteControl()
{
super();
_initializeButtons();
parent["myVoteContainer"].addEventListener(Event.ENTER_FRAME, _add);
this._count = 0;
this._pg = 0;
this._p_result=false;
this._intervalCount=0;
this._myVoteSequence = new Array();
this._videoPlayed=true;
this._demoHasBeenRest=false;
this._demoToggle=false;
 }

/*----------------Below is an example of the right button command ------------*/

private function _right(e:MouseEvent):void
{ trace("you clicked right"); 


if(parent["myVoteContainer"]["question_section_mc"].visible)
{
 _inc(); 
 _setSelection(_cyclePos(this._questionArray, this._count), this._questionArray);
}else if(parent["myVoteContainer"]["aj_rating_mc"].visible){
 _inc(); 
 _setSelection(_cyclePos(this._ratingArray, this._count), this._ratingArray);
}

if(parent["myVoteContainer"]["poll_results_mc"].visible || 
 parent["myVoteContainer"]["phone_number_field_mc"].visible || 
 parent["myVoteContainer"]["thank_you_mc"].visible)
{
 _incS();
 _setSelection(_rightLeft(this._votingArray, this._pg), this._votingArray);
 _setSelection(_rightLeft(this._phoneArray, this._pg), this._phoneArray);
 _setSelection(_rightLeft(this._thxArray, this._pg), this._thxArray);
 _mapAlternatePaths();
}

}

/*------------------ initialize buttons --------------------------------------*/


private function _initializeButtons():void
{
this["right_mc"].buttonMode = true;
this["right_mc"].addEventListener(MouseEvent.CLICK, _right);
this["right_mc"].addEventListener(MouseEvent.MOUSE_DOWN, _mouseDown); 
this["right_mc"].addEventListener(MouseEvent.MOUSE_UP, _mouseUp); 
this["right_mc"].addEventListener(MouseEvent.MOUSE_OUT, _mouseUp);
     }

//   Store VoteContainer page's nest movieclips in there own array -- will be used to navigate through them//

private function _add(e:Event):void
{
this._questionArray = new Array();
this._questionArray.push(parent["myVoteContainer"]["question_section_mc"]["answer1_hl_mc"]);
this._questionArray.push(parent["myVoteContainer"]["question_section_mc"]["answer2_hl_mc"]);
this._questionArray.push(parent["myVoteContainer"]["question_section_mc"]["answer3_hl_mc"]);
this._questionArray.push(parent["myVoteContainer"]["question_section_mc"]["answer4_hl_mc"]);

// Use to select which on the page to select //

private function _setSelection(val:int, arr:Array):void
{
for(var i:uint=0; i<arr.length; i++)
 {
  arr[i].visible=false;
 }

arr[val].visible=true;
}

  private function _cycleNeg(arr:Array, val:int=0):int
 {
  if(val<1)
  {
   this._count = arr.length;
  }else if(this._count>arr.length){
   this._count = 0;
  }

  trace(val);
  return val; 
 }
  private function _cyclePos(arr:Array, val:int=0):int
  {
   if(val<0)
 {
  this._count = arr.length;
 }else if(this._count>=arr.length){
 this._count = 0;
 }

trace(val);
return this._count; 
}

private function _cycleUp(arr:Array, val:int=0):int
 {
 if(val<0)
 {
  this._count = arr.length;
 }else if(this._count>=arr.length){
 this._count = 0;
}

trace(val);
return this._count; 
}

}