PDA

View Full Version : populate SWFLoader from SWF?


mspanish
04-28-2009, 11:48 PM
Hello there - I have 2 SWFloaders in my Flex app, that correspond to a content box for lessons, and a virtual tutor box for videos. All of the content are AS3 swfs. I want to place buttons in my content so that I can change out the SWFs in either of the SWFLoaders in the Flex app. Does anybody know the code I would need in order to do that in my Flex app, as well as in my FLA files? A really crude demo of our curriculum page is here (just working on coding at this point, design is only bones!)

http://www.instaspanish.com/images/sample.jpg

Here is the code I'm using to load the SWFLoaders in the Flex app:


<mx:Script>
<![CDATA[
import mx.events.ListEvent;

private function tree_itemClick(evt:ListEvent):void {
var t:Tree = evt.currentTarget as Tree;
var dataObj:Object = evt.itemRenderer.data;
if (dataObj.hasOwnProperty("@mainswf")) {
swfLoader.source = dataObj.@mainswf;
} else if (t.dataDescriptor.isBranch(t.selectedItem)) {
swfLoader.source = null;
panel.status = "";
}
}

private function tree_labelFunc(item:Object):String {
var suffix:String = "";
if (tree.dataDescriptor.isBranch(item)) {
suffix = " (" + item.children().length() + ")";
}
return item.@label + suffix;
}

private function swfLoader_complete(evt:Event):void {
panel.status = (swfLoader.bytesTotal/1024).toFixed(2) + 'KB';
}
]]>
</mx:Script>


<mx:Script>
<![CDATA[
import mx.events.ListEvent;

private function tree_itemClick2(evt:ListEvent):void {
var t:Tree = evt.currentTarget as Tree;
var dataObj:Object = evt.itemRenderer.data;
if (dataObj.hasOwnProperty("@tutorswf")) {
swfTeacher.source = dataObj.@tutorswf;
} else if (t.dataDescriptor.isBranch(t.selectedItem)) {
swfTeacher.source = null;
panel.status = "";
}
}

private function tree_labelFunc2(item:Object):String {
var suffix:String = "";
if (tree.dataDescriptor.isBranch(item)) {
suffix = " (" + item.children().length() + ")";
}
return item.@label + suffix;
}

private function swfTeacher_complete(evt:Event):void {
panel.status = (swfTeacher.bytesTotal/1024).toFixed(2) + 'KB';
}
]]>
</mx:Script>

If anybody has any ideas how to do this I'd be ecstatic to hear it!

warm wishes
Stacey

mspanish
04-29-2009, 09:53 AM
Turns out to be quite simple to do this - thanks to coder Samjain78 from getacoder.com. First the Flex code:

<mx:Script>
<![CDATA[

public function FromSwf1(value:String):void
{
swfLoader.source = value;
}

public function FromSwf2(value:String):void
{
swfTeacher.source = value;
}


]]>
</mx:Script>

Here is the AS3 code for 2 sample flash buttons, 1 for each of my SWFLoaders in the Flex app:

var flexApp = root.parent.parent['parentApplication'];
btn1.addEventListener(MouseEvent.CLICK, CallFlexFunction);
//stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
function CallFlexFunction(e:MouseEvent) {
flexApp.FromSwf1("assets/ninos/alphabet.swf");
}

btn2.addEventListener(MouseEvent.CLICK, CallFlexFunction2);
//stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
function CallFlexFunction2(e:MouseEvent) {
flexApp.FromSwf2("assets/ninos/clase_de_ninos.swf");
}

Works great!

sonicnguyen
04-29-2009, 11:00 AM
Hi Everybody
I just have been finish some website by flash.
Pls give me some ideal about this site
Thanks
Best Regards
http://www.idesign.com.vn/sonicpro/index.html
http://www.idesign.com.vn/