I'm trying to set up a proof-of-concept of loading one SWF into another SWF for skinning. The set-up is this:
app.fla
, which has an attached ActionScript class,AppMain.as
skin.fla
, which contains UI components
AppMain.as
will obviously contain all of the application's logic; I then want to be able to affect the UI components contained within the loaded skin file based on instance names defined in that particular skin.
So for example, if I have a TextField
with an instance name of myTextField
I'd like to be able to set the text
property of that text field programmatically in AppMain.as
.
The exported app.swf
to load a skin file based on a flashvar
parameter would be loaded into an HTML document that looked like this:
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="swf"><!--//--></div>
<script src="jquery.js"></script>
<script src="swfobject.js"></script>
<script>
$(document).ready(function() {
$('#swf').flash({
swf: 'app.swf',
width: 550,
height: 400,
flashvars: {
skin: 'skin.swf'
}
});
});
</script>
</body>
</html>
This simply loads app.swf
into the #swf
<div>
. Any help on how to get the skin SWF into my main app SWF would be grateful. I currently have the following (which does not work).
package
{
import flash.display.Loader;
开发者_JAVA百科 import flash.display.MovieClip;
import flash.net.URLRequest;
public class AppMain extends MovieClip
{
public function AppMain()
{
var myLoader:Loader = new Loader();
self.addChild(myLoader);
var myRequest:URLRequest = new URLRequest('skin.swf');
myLoader.load(myRequest);
}
}
}
The skin I'm trying to load is simple in that it has a red background so I can see if it's been loaded or not; it's not as my HTML page where I'm exporting to still has a white background.
Do I have an error above? The console in Flash Professional CS5 is not giving me any errors under the "Compile Errors" tab.
I tried your code with smaller modifications and it worked fine for me. First of all check this line:
self.addChild(myLoader);
If your code what you wrote here is complete, the self variable is not declared (but in this case you should get an "Access of undefined property" error). If that variable is declared, check that is added to the display list or not. Your problem can be reproduced in that case when it not added: you don't see your loaded stuff, and don't get any errors.
If it still not helps, try to add some event listeners to your Loader instance to see what happening during the load process.
myLoader.contentLoaderInfo.addEventListener( Event.INIT, initHandler );
myLoader.contentLoaderInfo.addEventListener( Event.OPEN, openHandler );
myLoader.contentLoaderInfo.addEventListener( Event.UNLOAD , unLoadHandler );
myLoader.contentLoaderInfo.addEventListener( Event.COMPLETE , completeHandler );
myLoader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR , ioErrorHandler );
myLoader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS , progressHandler );
myLoader.contentLoaderInfo.addEventListener( HTTPStatusEvent.HTTP_STATUS , httpStatusHandler );
myLoader.contentLoaderInfo.addEventListener( SecurityErrorEvent.SECURITY_ERROR , securityErrorHandler);
If you have any other questions, please ask.
Cheers
Tamas Gronas
精彩评论