actionscript-3flash-cs5.5adobe-captivate

AS3 "import packages" not working - drag and drop game in captivate


I'm trying to put an AS3 "drag and drop" game onto a slide in captivate 6. The standalone swf works fine but as soon as it is imported onto a slide in captivate and you publish it, captivate re-wraps all its content into another swf thus losing the imported game packages.

On the main timeline in flash i have the action

import com.test.games.*;

var dragArray:Array = [comment1, comment2, comment3, comment4, comment5, comment6, comment7, comment8 ];
var matchArray:Array = [leftMatch, leftMatch, rightMatch, rightMatch, rightMatch, leftMatch, rightMatch, leftMatch ];
var posArray:Array = [ {x:154, y:362}, {x:154, y:316}, {x:641, y:362}, {x:641, y:316}, {x:641, y:270}, {x:154, y:270}, {x:641, y:224}, {x:154, y:224} ];

var dragGame:DragGame = new DragGame(stage, dragArray, matchArray, posArray);

dragGame.addEventListener(DragGame.MATCH_MADE, onMatch);
dragGame.addEventListener(DragGame.NO_MATCH, onFlub);
dragGame.addEventListener(DragGame.ALL_DONE, onDone);

function onMatch(event:Event):void {
    var matchSound:Sound = new MatchSound();
    matchSound.play();
}
function onFlub(event:Event):void {
    var flubSound:Sound = new FlubSound();
    flubSound.play();
}
function onDone(event:Event):void {
    var applause:Sound = new Applause();
    applause.play();
}

But i think what is causing the problem is that the 4 package files from

import com.test.games.*;

are being lost when re-wrapped in captivate's swf, if that makes sense?

Do i need to target root or something for it to work, or is there a way of nesting the packages for all the files with the main timeline.

(the game is a freebie i have found - so i'm not majorly confident with AS3 as a language please be gentle)


Solution

  • I expect it's because the stage value can be null when you import this into Captivate. Override with this:

    var dragGame:DragGame; // uninitialized!
    if (stage) init() else addEventListener(Event.ADDED_TO_STAGE,init);
    function init(e:Event=null):void {
        removeEventListener(Event.ADDED_TO_STAGE,init);
        // here we have stage available, let's make a game
        dragGame = new DragGame(stage, dragArray, matchArray, posArray); 
        dragGame.addEventListener(DragGame.MATCH_MADE, onMatch);
        dragGame.addEventListener(DragGame.NO_MATCH, onFlub);
        dragGame.addEventListener(DragGame.ALL_DONE, onDone);
    }