Thanks for the reply Matt.
I've figured out a few things, but this is the main problem:
We want to have one Flash file called JJHUD.swf, which in turn loads multiple flash files such as Inventory.swf, Puzzle.swf, Memo.swf and few couple others. In all of them we want to use CLIK components for buttons etc. I managed to load multiple SWF files using the Loader class, and switch between them, but as soon as I started adding CLIK components into them, I get all kinds lot of reference errors.
How should I approach this setup?
At the moment JJHUD.swf has JJHUD.as as it's Class in the document properties. Inside JJHUD.as it's extending the UIComponent class like this:
Code:
package
{
import flash.display.MovieClip;
import flash.ui.Mouse; //To modify the normal mouse stuff, like hiding it
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.events.IEventDispatcher;
import flash.display.Loader;
import flash.net.URLRequest;
import scaleform.gfx.Extensions; //To enable GFx Extensions
import flash.external.ExternalInterface; //To enable talking to Unreal code
import flash.system.fscommand; //To Enable the HACK way of communicating with Unreal (for testing purposes)
import scaleform.clik.core.UIComponent;
import scaleform.clik.events.ButtonEvent;
import scaleform.clik.constants.InvalidationType;
import scaleform.clik.controls.Button;
public dynamic class JJHUD extends UIComponent
{
/** Varibles */
public var _swfLoader:Loader;
public var _swfRequest:URLRequest;
public var _swfPathArr:Array = new Array("Dialogue/Dialogue.swf", "Inventory/Inventory.swf", "Puzzle/Puzzle.swf", "Hints/Hints.swf", "Memo/Memo.swf");
//public var _swfPathArr:Array = new Array("Puzzle/Puzzle.swf");
public var _swfClipsArr:Array = new Array();
public var _swfTempClip:MovieClip;
public var _loadedSWFs:int;
public var contentCont:MovieClip;
public var mouseCursor:MovieClip;
public var loadInventory:Button;
public var loadHints:Button;
public var loadMemo:Button;
public var loadPuzzle:Button;
public var loadDialogue:Button;
public var loadEmpty:Button;
/** Constructor */
public function JJHUD():void
{
super();
}
override protected function configUI():void
{
super.configUI();
// Hide the normal mouse cursor
Mouse.hide();
/* Start loading the external swf files */
startLoading(_swfPathArr);
}
override protected function draw():void {
super.draw();
}
private function addListeners():void
{
// Update mouse cursor
stage.addEventListener( MouseEvent.MOUSE_MOVE, moveMouseCursor, false, 0, true );
// DEBUG:
stage.addEventListener(MouseEvent.MOUSE_DOWN, stageDown);
stage.addEventListener(MouseEvent.MOUSE_UP, stageUp);
stage.addEventListener(MouseEvent.MOUSE_OVER, stageOver);
stage.addEventListener(MouseEvent.MOUSE_OUT, stageOut);
loadInventory.addEventListener(MouseEvent.CLICK, setContent);
loadHints.addEventListener(MouseEvent.CLICK, setContent);
loadMemo.addEventListener(MouseEvent.CLICK, setContent);
loadPuzzle.addEventListener(MouseEvent.CLICK, setContent);
loadDialogue.addEventListener(MouseEvent.CLICK, setContent);
loadEmpty.addEventListener(MouseEvent.CLICK, setContent);
}
function startLoading(pathArr:Array):void {
//_swfLoader = new Loader();
_swfRequest = new URLRequest();
loadSWF(pathArr[0]);
}
function loadSWF(path:String):void {
_swfLoader = new Loader(); //<- needed to work in Scaleform
setupListeners(_swfLoader.contentLoaderInfo);
_swfRequest.url = path;
_swfLoader.load(_swfRequest);
}
function setupListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, onSwfComplete);
dispatcher.addEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
}
function currentSwfProgress(event:ProgressEvent):void {
var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
// swfPreloader.percentTF.text = _perc + "%";
}
function onSwfComplete(event:Event):void
{
event.target.removeEventListener(Event.COMPLETE, onSwfComplete);
event.target.removeEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
_swfTempClip = event.target.content;
//_swfTempClip.customID = _loadedSWFs;
_swfClipsArr.push(_swfTempClip);
if(_loadedSWFs <_swfPathArr.length - 1) {
_loadedSWFs++;
loadSWF(_swfPathArr[_loadedSWFs]);
} else {
onCompletePreloading();
}
}
function onCompletePreloading():void {
trace("_swfClipsArr[0]: " + _swfClipsArr[0])
contentCont.addChild(_swfClipsArr[0]);
/* Add listeners */
addListeners();
}
function setContent(event:MouseEvent):void {
var _swfToAdd:MovieClip;
for (var j:uint = 0; j < _swfClipsArr.length; j++){
trace("_swfClipsArr[i]:" +_swfClipsArr[i].name);
}
switch(event.target.name)
{
case "loadDialogue":
_swfToAdd = _swfClipsArr[0];
break;
case "loadInventory":
_swfToAdd = _swfClipsArr[1];
break;
case "loadPuzzle":
_swfToAdd = _swfClipsArr[2];
break;
case "loadHints":
_swfToAdd = _swfClipsArr[3];
break;
case "loadMemo":
_swfToAdd = _swfClipsArr[4];
break;
case "loadEmpty":
_swfToAdd = _swfClipsArr[0];
break;
}
contentCont.removeChildAt(contentCont.numChildren-1);
contentCont.addChild(_swfToAdd);
trace(_swfToAdd.customID);
for (var i:uint = 0; i < contentCont.numChildren; i++){
trace("contentcont: "+contentCont.getChildAt(i).name);
}
}
//*******************
// MOUSE CURSOR MOVEMENT
//*******************
private function moveMouseCursor( e:MouseEvent ):void
{
mouseCursor.x = e.stageX;
mouseCursor.y = e.stageY;
}
//*******************
// STAGE EVENTS
//*******************
function stageDown(e:MouseEvent) : void
{
trace("--Stage down at: " +mouseX +" / " +mouseY);
trace(" target: " +e.target + " target.name: " + e.target.name);
}
function stageUp(e:MouseEvent) : void
{
trace("--Stage up at: " +mouseX +" / " +mouseY + " obj: " + e.relatedObject);
trace(" target: " +e.target + " target.name: " + e.target.name);
}
function stageOver(e:MouseEvent) : void
{
trace("--Stage over at: " +mouseX +" / " +mouseY + " obj: " + e.relatedObject);
trace(" target: " +e.target + " target.name: " + e.target.name);
}
function stageOut(e:MouseEvent) : void
{
trace("--Stage out at: " +mouseX +" / " +mouseY + " obj: " + e.relatedObject);
trace(" target: " +e.target + " target.name: " + e.target.name);
}
} // End Class
} // End Package
Apart from the Puzzle/Puzzle.swf, the other files don't have any CLIK components and work well (their classes extending from MovieClip). The Puzzle.swf's class is Puzzle.as, which like JJHUD extends from UIComponent. In the Puzzle.fla the only object in it is a button with instance name of continueBtn.
Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import scaleform.clik.core.UIComponent;
import scaleform.clik.events.ButtonEvent;
import scaleform.clik.constants.InvalidationType;
import scaleform.clik.controls.Button;
public dynamic class Puzzle extends UIComponent
{
/* Vars from the scene */
//public var puzzleNumberLabel:DefaultLabel;
//public var puzzleNameLabel:DefaultLabel;
//public var puzzleMeritsLabel:DefaultLabel;
//public var contentContainer:MovieClip;
//public var myTextField:DefaultTextArea;
public var continueBtn:Button;
//public var customID:String;
public function Puzzle()
{
// constructor code
super();
}
override protected function configUI():void
{
super.configUI();
//Set up stuff like names:
//continueBtn.label = "Start Puzzle";
//Call for listeners to be added:
addListeners();
}
override protected function draw():void {
super.draw();
}
private function addListeners()
{
//continueBtn.addEventListener(MouseEvent.MOUSE_UP, handleContinueBtn);
}
private function handleContinueBtn()
{
if(this.currentLabel == "StartSlide")
{
gotoAndStop(5);
//continueBtn.label = "Finish Puzzle";
} else if(this.currentLabel == "PuzzleContent")
{
gotoAndStop(10);
//continueBtn.label = "Close Puzzle";
} else if(this.currentLabel == "EndSlide")
{
gotoAndStop(1);
//continueBtn.label = "StartSlide";
}
}
}
}
Alone, the Puzzle.swf works fine. But when I try to run the JJHUD in the Scaleform player, I get this:
Code:
Error: TypeError: Error #1009: Cannot access a property of null object reference.
at Puzzle/__setProp_continueBtn_Scene_baka_0()
at Puzzle instance constructor()
And yes, the Puzzle.swf has a Button with instance name of continueBtn in it's frame 1 (on layer baka).
Funny thing, just 'till moment ago I got another error as well about not being able to create object called contentContainer in the Puzzle, which is an object I had deleted ages ago and commented out the definition as well. Somehow the linking seems to be a bit broken as well.
But yes, any help with setting up a system like this would be massively welcomed!
Bookmarks