Page 1 of 1

Flex / Example 7

Posted: Sun Jul 06, 2008 8:55 pm
by fender
Hi

I have just made my first Hello World application. I am using example 7 and I have made a small Flex 3 program instead of the flash .swf file. The program looks like this:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<mx:Application initialize="init();" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
   <mx:Button id="mine" x="10" y="10" label="Button"/>
   <mx:Script>
      <![CDATA[
         import flash.external.*;
         private function init() : void {
            ExternalInterface.addCallback("CallMeFromApplication", InternalFunction);
         }
         public function InternalFunction(str: String): String {
            mine.label = "Hey";
            return ":random" + Math.random();
         }
      ]]>
   </mx:Script>
</mx:Application>


I correctly get a new random number back to the c# application but the label on the button will not change. It seems like I have two instances. One visible - and one invisible which recieves the calls

Does anybody know how to fix this?

Ben

Problem solved

Posted: Thu Jul 17, 2008 6:09 pm
by fender
I found the solution to my problem

The line:

Code: Select all

f_in_box__control1.FlashMethod_Play();


Must be removed. For some reason it creates a new instance - and then I have one visible and one invisible.
Both instances can call my C# code, but my C# code can only call the invisible instance.

Maybe the example should be extended with

Code: Select all

// The following line must be removed if the .swf file is created using Flex
f_in_box__control1.FlashMethod_Play();


/Ben

Posted: Fri Jul 18, 2008 11:47 am
by Softanics
Yes, you're right...

Thank you for this information, we will update the samples.

Thank you.