PDA

View Full Version : ExternalInterface breaks swf


canarchy
07-19-2011, 08:29 PM
I have a weird problem here in which my mxml compiles fine but when I load it in the webpage all it shows is a black box....

I have isolated the cause to be line 46 which is
ExternalInterface.addCallback("toggle",playerToggle);

Can't seem to find anybody on Google who has the same issue....

Here is my entire script:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="[...]"
layout="absolute" usePreloader="false"
applicationComplete="init()"
backgroundColor="#000000"
backgroundAlpha="1">

<!-- Load styles -->

<mx:Script>

// Imports
import flash.external.ExternalInterface;
import mx.core.FlexGlobals;

// Important variables
private var nc:NetConnection; // net connection
private var stream:NetStream; // net stream
private var video:Video; // video
private var meta:Object; // meta data


// This succker is loaded. Act like it.
private function init():void
{
// No scaling
stage.scaleMode = StageScaleMode.NO_SCALE;

// Flash Vars
var params:Object = FlexGlobals.topLevelApplication.parameters;

/* Not right now
if( params.stylesheet )
{
FlexGlobals.topLevelApplication.styleManager
.loadStyleDeclarations( params.stylesheet );
}*/

// Position
playBox.width = overlay.width = stage.stageWidth;
playBox.height = overlay.height = stage.stageHeight;



// External Callbacks
ExternalInterface.addCallback("toggle",playerToggle);

// add event to overlay
overlay.addEventListener(MouseEvent.CLICK, overlayClick);

// Start handling video stuff
var nsClient:Object = {};
nsClient.onMetaData = ns_onMetaData;
nsClient.onCuePoint = ns_onCuePoint;

nc = new NetConnection();
nc.connect(null);

stream = new NetStream(nc);
stream.play("video.flv");
stream.pause();
stream.seek(0);
stream.client = nsClient;

// create the video object
video = new Video();
video.attachNetStream(stream);

playBox.addChild(video);

video.width = stage.stageWidth;
video.height = stage.stageHeight;


}

// Meta and cue
private function ns_onMetaData(item:Object):void {
trace("meta");
meta = item;
// Resize Video object to same size as meta data.

var w:Number, h:Number;
if( item.width > stage.stageWidth )
{ w = stage.stageWidth; }
else
{ w = item.width; }
if( item.height > stage.stageHeight )
{ h = stage.stageHeight; }
else
{ h = item.height; }

video.width = w;
video.height = h;

var diffW:Number = stage.stageWidth-w;
var diffH:Number = stage.stageHeight-h;

video.x = diffW/2;
video.y = diffH/2;
}

private function ns_onCuePoint(item:Object):void {
trace("cue");
}

// some other stuff

// overlay clicked
private function overlayClick(event:Event):void
{
playerToggle();
}


// in player commands, only accessible in house
public function playerToggle():void
{
stream.togglePause();
}



</mx:Script>

<mx:UIComponent id="playBox" x="0" y="0">
</mx:UIComponent>
<mx:Canvas id="overlay" backgroundColor="#FFFFFF" backgroundAlpha="0" x="0" y="0"/>

</mx:Application>


Thanks for any help you can give me.

Edit:
Without that line everything works great just without the access via javascript.

canarchy
07-19-2011, 10:01 PM
Never mind. Accidentally opened the file through the explorer instead of the localhost.... It works.