C# XML to FLASH/FLEX and FLASH/FLEX XML to C#

.NET Edition of the F-IN-BOX
danielgianni
Posts: 8
Joined: Thu Nov 22, 2007 1:33 pm

C# XML to FLASH/FLEX and FLASH/FLEX XML to C#

Postby danielgianni » Wed Jan 30, 2008 9:56 pm

How can I spend a XML for the C # for Flash / Flex and move back a XML Flash / Flex for the C #?

I need to make the communication of data between the C # and Flash / Flex.

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Re: C# XML to FLASH/FLEX and FLASH/FLEX XML to C#

Postby Softanics » Thu Jan 31, 2008 6:23 am

Thank you for your question.

danielgianni wrote:How can I spend a XML for the C # for Flash / Flex and move back a XML Flash / Flex for the C #?

I need to make the communication of data between the C # and Flash / Flex.


In Actionscript you write:

Code: Select all

var xml1:xml = new xml();
xml1.load("data.xml");


In C# you handle event OnLoadExternalResourceByRelativePath:

Code: Select all

private void OnLoadExternalResourceByRelativePath(object sender, string strRelativePath, Stream Stream, ref bool Handled)
{
    if (strRelativePath == "data.xml")
    {
        Stream.Write(...); // write XML here
        bHandled = true;
    }
}


It's how to pass an XML from C# to Actionscript.

To pass data from Actionscript to C# you can use external API.
Best regards, Artem A. Razin,
F-IN-BOX support
Ask your question here: http://www.f-in-box.com/support.html

danielgianni
Posts: 8
Joined: Thu Nov 22, 2007 1:33 pm

Thanks!

Postby danielgianni » Thu Jan 31, 2008 3:45 pm

But that applies to f-in-box? Sorry my question but i don't know.

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Re: Thanks!

Postby Softanics » Thu Jan 31, 2008 3:56 pm

danielgianni wrote:But that applies to f-in-box? Sorry my question but i don't know.


Yes. You can see the important feature: with f-in-box you can handle external resources. As file 'data.xml' in the example above.
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html

danielgianni
Posts: 8
Joined: Thu Nov 22, 2007 1:33 pm

Only once time

Postby danielgianni » Thu Jan 31, 2008 4:13 pm

If I do not have the XML file, but I have only one XML structure in memory even if is possible the communication?

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Re: Only once time

Postby Softanics » Thu Jan 31, 2008 4:19 pm

danielgianni wrote:If I do not have the XML file, but I have only one XML structure in memory even if is possible the communication?


Yes, you load XML from a virtual / fake file, 'data.xml'. There is no such file, but your code provides the data of this virtual file:

Flash movie tries to load 'data.xml':

Code: Select all

var xml1:xml = new xml();
xml1.load("data.xml");


2. f-in-box calls your event handler:

Code: Select all

private void OnLoadExternalResourceByRelativePath(object sender, string strRelativePath, Stream Stream, ref bool Handled)
{
    if (strRelativePath == "data.xml")
    {
        Stream.Write(...); // write XML here
        bHandled = true;
    }
}


3. Flash thinks that the file 'data.xml' is really exists and uses the data you've just provided here:

Code: Select all

Stream.Write(...); // write XML here
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html

Roomie
Posts: 22
Joined: Wed Dec 19, 2007 6:05 am

Postby Roomie » Thu Jan 31, 2008 4:26 pm

Another way, if you dont have the xml data in a file, is to use the ExternalInterface.call function in ActionScript. With that you can pass xml data from Flash to your hosting C# application and then the return object should be in xml.

In ActionScript:

Code: Select all

import flash.external.ExternalInterface;

var myXML;

function GetXML()
{
    myXML = ExternalInterface.call("GetXML");
}

function SendXML()
{
    ExternalInterface.call("SendXML", "<string>Hello C#</string>");
}


In C#

Code: Select all

private XmlNodeList MyXmlList = new XmlNodeList();

private void FlashControl_OnFlashCall(object sender, string request)
{
    XmlDocument FlashXMLDoc = new XmlDocument();
    FlashXMLDoc.LoadXml(request);
   
    string strCommand = FlashXMLDoc.GetElementsByTagName("invoke").Item(0).Attributes.GetNamedItem("name").Value;
   
    XmlNodeList list = FlashXMLDoc.GetElementsByTagName("arguments");
   
    if (strCommand == "GetXML")
    {
        String ReturnString = "<string>Hi Flash</string>";  // XML Data to send in this case just a string
       
        FlashControl.FlashMethod_SetReturnValue(ReturnString); //Send the list to Flash
       
        //MessageBox.Show(ReturnString);
    }

    if (strCommand == "SendXML")
    {
        MyXmlList = list;
    }
}


Hope this helps.

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Thu Jan 31, 2008 5:18 pm

Roomie, thank you! Good example.
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html

danielgianni
Posts: 8
Joined: Thu Nov 22, 2007 1:33 pm

Thanks!

Postby danielgianni » Thu Jan 31, 2008 5:47 pm

It's cool support. Thanks for all!


Return to “.NET Edition”

Who is online

Users browsing this forum: No registered users and 29 guests

cron