I am completely new to ActionScript. I am nesting an SWF in another SWF container to be able to send the clicks from the flash object to the javascript outside. I am able to receive the clicks outside and that part works fine. But the inner content is not scaled to the size of the outer container. I use mxmlc from the 3.5 SDK, without any additional parameters except the actionscript filename, to compile the actionscript to SWF. How can I make the inner content fill up the container?
Here's the ActionScript:
package
{
import flash.external.ExternalInterface;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
[SWF(backgroundColor="#ffff00", frameRate="24")]
public class Container extends MovieClip
{
private var loader:Loader = new Loader();
private var textfield : TextField = new TextField();
public function Container()
{
root.addEventListener( MouseEvent.CLICK, useExternal, true );
var request:URLRequest = new URLRequest("adv.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_OnComplete);
loader.addEventListener(MouseEvent.CLICK, loader_OnClick);
loader.load(request);
addChild( textfield );
}
private function loader_OnComplete(event:Event):void
{
textfield.text = stage.stageWidth + ", " + stage.stageHeight;
textfield.autoSize = TextFieldAutoSize.LEFT;
textfield.setTextFormat(new TextFormat(null,48));
textfield.x = stage.stageWidth - textfield.width;
textfield.y = stage.stageHeight / 2 - textfield.height / 2;
loader.content.width = stage.stageWidth;
loader.content.height = stage.stageHeight;
addChild(loader);
}
private function loader_OnClick(event:MouseEvent):void
{
ExternalInterface.call( "swfClickFunction" );
}
private function useExternal(event:MouseEvent):void
{
ExternalInterface.call( "ExternalFunction" );
}
}
}
And the HTML:
<html>
<head>
<script language="javascript">
function swfClickFunction()
{
alert('Flash Clicked!');
}
function ExternalFunction()
{
alert('ExternalFunction!');
}
</script>
<body>
<OBJECT
name = Container
id = Container
codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0
width = 800
height = 80
classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000>
<PARAM NAME="movie" VALUE='Container.swf'>
<PARAM NAME="quality" VALUE="high">
<embed
name='Container'
id='Container'
src='Container.swf' quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash"
width='800'
height='80'>
</embed>
</OBJECT>
</body>