Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

(Solved)[AS2] Populating buttons on HUD

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    (Solved)[AS2] Populating buttons on HUD

    I'm probably going about this the wrong way, but I can't think of another way to accomplish the task.

    Overview:
    I'm trying to reproduce one of the basic RTS functionality, displaying all selected units on the hud as clickable buttons that, when clicked will display the stats of that specific unit.

    So Far:

    - In the flash file I have a simple array> var groupUnits:Array = new Array();
    - In UDK I have a dynamic array> var array<MyUnit> groupedUnits;
    - I've got a marquee selection that grabs every unit I have selected and stores them inside of groupedUnits on button release> groupedUnits.AddItem(unit);
    - As soon as I add the unit to the dynamic array, I also add a reference to it's index in my flash file> HudMovie.populateMassSelect(groupedUnits.Length - 1);
    - The flash function pushes the index inside of the array inside of populateMassSelect(identifier:Number):Void > groupUnits.push(identifier);
    - On left mouse button release, after adding the units to the array, I call a unitSelectPanel in case the groupedUnits.Length is not 0
    - In flash the unitSelectPanel():Void does a good number of attachMovie() for every unit inside of the groupUnits array.
    Code:
    function unitSelectPanel():Void
    {
    		var xVal:Number = 10;
    		var yVal:Number = 10;
    		var wVal:Number = 44.50;
    		var hVal:Number = 40.45;
    		var margin:Number = 0.5;
    		
    		//add the MassSelectArea to the screen
    		if(!_root.MassSelect)
    		{
    			_root.attachMovie('MassSelectArea', 'MassSelect', _root.getNextHighestDepth());
    		}
    		
    		if(_root.MassSelect)
    		{
    			//Set our coords to be on top of the unit display
    			MassSelect._x = 410;
    			MassSelect._y = 535;
    			
    			//Create buttons for each unit in the array
    			for(var i=0; i < groupUnits.length; i++)
    			{
    				if(!MassSelect["Unit"+i] && i < 36)
    				{
    					MassSelect.attachMovie('UnitRadialButton', 'Unit'+i, MassSelect.getNextHighestDepth());
    				}
    			}
    
    			//Place buttons properly
    			for(var i=0; i < groupUnits.length; i++)
    			{
                                    //Only display a specific maximum of buttons
    				if(MassSelect["Unit"+i] && i < 36)
    				{
    					
    					//Add the click event listener
    					MassSelect["Unit"+i].disableFocus = true;
    					MassSelect["Unit"+i].data = groupUnits[i];
    					MassSelect["Unit"+i].addEventListener("click", this, "massSelectSingle");
    					
    					//Split buttons to 12 per row
    					if(i < 12)
    					{
    						MassSelect["Unit"+i]._x = xVal + (i * (wVal + margin));
    						MassSelect["Unit"+i]._y = yVal;
    					}
    					else if(i < 24)
    					{
    						MassSelect["Unit"+i]._x = xVal + ((i - 12) * (wVal + margin));
    						MassSelect["Unit"+i]._y = yVal + (hVal + margin);
    					}
    					else if(i < 36)
    					{
    						MassSelect["Unit"+i]._x = xVal + ((i - 24) * (wVal + margin));
    						MassSelect["Unit"+i]._y = yVal + 2 * (hVal + margin);
    					}
    				}
    			}
    		}
    	
    }
    - Every single button will trigger the massSelectSingle(event:Movieclip):Void function which contains a simple udk function call> ExternalInterface.call("SingleMassUnitSelect", event.target.data)

    I would like to say that everything works as intended, but the problem comes when the button is pressed. I'm clearing the groupedUnits array in UDK on left mouse button press. So when the SingleMassUnitSelect function triggers and tries to set my selected unit to the value the array contains at that index ... well it's out of bounds because it no longer exists.

    - When I clear the UDK array, I also have to clear the HUD array, so my cleanup function is
    Code:
    function ClearGroupedUnits()
    {
        //tried groupedUnits.Empty but it errors out
        groupedUnits.Remove(0, groupedUnits.Length);
        HudMovie.cleanupArray();
    }
    - Inside my HUD I cleanup by destroying everything that I have previously created
    Code:
    function cleanupArray():Void
    {
    	if(_root.MassSelect)
    	{
    		for(var i=0; i < groupUnits.length; i++)
    		{
    			if(MassSelect["Unit"+i])
    			{
                                    //Kill the button
    				MassSelect["Unit"+i].removeMovieClip();
    			}
    		}
                    //Kill the background for the buttons
    		_root.MassSelect.removeMovieClip();
    	}
            //Empty the array of units
    	groupUnits = new Array();
    }
    Is there a better way of accomplishing what I'm trying to do? It doesn't make sense to have the click event listeners in the
    Code:
    event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
    because they need to be created in the .fla file from the start, correct? You can't reference what doesn't exist at the moment the flash file is loaded.

    Is there anything in scaleform that can disable the left click in udk when clicking on a scaleform button? Am I even approaching this train of thought properly? Any advice is welcome

    EDIT: I feel silly now, my problem was doing things on left button press instead of release. As soon as I called ClearGroupedUnits(); on release, everything worked as intended. Sometimes it helps to read over your question in the forums multiple times, you end up finding the answer to your own problem
Working...
X