Hrm... this line:

myMC.myRect = this.source();   //get function reference.

I think is backwards.  Like, this.source() fires the function that shows the 
alert.  You're writing it like myMC is supposed to hold the return value of 
the source function, but the source function doesn't return anything. 
Additionally, while myMC.myRect is a reference to the function, does the box 
actually get drawn in the SWF when you click the button?

:: goes to try this + Jason's code ::


----- Original Message ----- 
From: "sufibaba" <[EMAIL PROTECTED]>
To: <flexcoders@yahoogroups.com>
Sent: Wednesday, February 08, 2006 9:47 PM
Subject: [flexcoders] Got embed SWF to call a function in Flex


Hi guys,

Check this out, if you make the following changes to Jason Wong's
little example, then SWF is able to call a function in Flex2.  I got
it to fire a function -- no sending of arguments yet.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml";
xmlns="*" layout="absolute">
   <mx:Script>
   <![CDATA[
import mx.controls.Alert;
public var arg:String;

private function onClick(): void
{
var swf: MovieClip = MovieClip(myLoader.content);
var myMC: MovieClip = MovieClip(swf.getChildByName("myMC"));
myMC.myRect = this.source();   //get function reference.

}

         public function  source():void {
  Alert.show ("callback");
        }

]]>
</mx:Script>

<mx:Loader id="myLoader" x="5" y="5" source="SimpleSWF.swf"/>
<mx:Button x="10" y="167" label="Button" click="onClick()"/>
</mx:Application>


In the myClip.as file -- By the way, in order to get jason's
Simple.swf to compile in the flash IDE, you'll need to change the
following:

1. MyClip movie Linkage from "MyClip" to "myClip"
2. Change the "MyClip.as" file name to "myClip"


Make the following changes to myClip.as
-----------------------------------------------------------------

class myClip extends MovieClip

{


function set myRect(funcRef: Object): Void
{
_parent.lineStyle(2, 0xff0000);
_parent.moveTo(60, 60);
_parent.lineTo(200, 60);
_parent.lineTo(200, 100);
_parent.lineTo(60, 100);
_parent.lineTo(60, 60);


funcRef;

}


}

-----------------------------------------------------------------

What should happen....  If you click on the button it should popup an
Alert box displaying the word "callback"

Cheers,

Tim













--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to