Ana içeriğe atla

Flash AS3, ASP.NET and MSSQL connectivity

To connect your flash actionscript project to a database the easiest way is to use dynamically creating XML method.

With this code snippet you may load xml file into swf. If you implement MyDataXML.aspx as responsing XML file flash will accept it as an xml file.

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest(“ MyDataXML.aspx”));

function loadXML(e:Event):void
{
xml = new XML(e.target.data);
trace(xml);
}


To make an aspx file responsing XML file this code block you should write into page_load method.

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.Buffer = true;
response.ClearContent();
response.ClearHeaders();
response.ContentType = "text/xml";
xmldata="xml comes here";
response.Write(xmldata);

response.End();


This query sample may help you getting your data from database. This is not obligated. Just select your data however you like.

select *
from chairsAndTable
for xml path ('yourTagName')

As an alternate to this query i have written a custom method that turns my DataSet to XML file then I can select all i want (also able to join tables or implement trees).

In my opinion, this is the easiest and flexible way to connect your flash to database. If you have any other ways please let me know about it. ;)

PS: Do not forget to add document properties as the first line into XML file.


Yorumlar

Unknown dedi ki…
Öncelikle verdiğniz bilgiler için teşekkürler.

Ben XML doyalarını okumak için sizin bahsettiğinize benzer sadece daha önceden oluşturulmuş xml dosyasını okuyorum
loader.load(new URLRequest(“ denme.xml”));
gibi. Ama burdakı sorun bu xml de flashla birlikte indirildiğinden siteyi refresh ettiğimizde xml değişmişse bile bunu göremiyoruz değişiklikleri görmek için geçmişi temizlememiz gerekiyor.

Benim sorum bu yöntem uygulandığında bu sorun aşılmış olurmu.

P.S. önce ingilizce yazayım dedim yeterince anlatamadım o yüzden türkçe yazdım teşekkürler
_Selim dedi ki…
loader.load(new URLRequest(“ denme.xml”)); isteğini loader.load(new URLRequest(“ denme.xml?xyz=12345”)); şeklinde, 12345 yerine random sayı üreterek çağırırsan her isteğinde farklı bir dosya çağırıyormuş gibi davranır ve browser cache e takılmamış olursun.
Unknown dedi ki…
PHP için amfPhp diye bişi var ve veri tabanından veriler XML göre çok daha hızlı ve kolay bir şekilde okunabiliyor. Benzer bir şey ASP içinde varmı bu konuda bilginiz varmı?
Teşekkürler