Flash Widget Tutorial

Flash Widget Tutorial screenshot

Text-only Preview

Flash WidgetsHussain Fakhruddinhttp://[email protected] :ޔWindow Gadgets➔Can be embedded on ➔ Websites, ➔ Blogs, ➔ Desktops,➔ Social networking sites ...➔Really easy to develop➔Many Frameworks2Widgets widgets widgets3What are we waiting for?What we're going to do is this:Retrieve data from a database.Print it somewhere using scripting language.Import this in the flash.What we need?Adobe Flash( I'l show al demos using Flash 8)PHP/ASP/JSP/CGI/RoR any scripting language. I'l use PHPDatabase if any.4Lets get startedOn the server.Step 1: (Without XML)Create a script which wil throw out the data to you in a GET variable formExample author=Hussain&desc=I+am+a+stupid+programmer&picurl=me.jpgAlso create a database create table barcamp(uid int(10) primary key auto_increment,author varchar(50),desciption text,picurl varchar(60));5PHP Script for the widget<?php$uid = $_GET['uid']; // I will receive this from the flashinclude ('db.php'); //Contains my Database Connectivity code.$rs = mysql_query("select * from barcamp where uid=$uid");// I'm being lazy to check for errors here$arr = mysql_fetch_array($rs);//Output format, I am using URL encode method, One may also use XMLecho "author=".$arr['author'];echo "&desc=".$arr['desciption'];echo "&picurl=".$arr['picurl'];?>6Flash DesignOur flash widget design7Flash ActionScriptNow to get this data into our flash widgetfunction LoadData() {myvar=new LoadVars(); //Create a New LoadVars object//Load our created URLmyvar.load("http://www.mywidgets.com/widget/getWidgetInfo.php?uid=" + this.uid);//I'll explain where this.uid comes from later.myvar.onLoad = function( ){/* Our PHP variables are available inside flash asmyvar.author;myvar.desc;myvar.picurl;*/author = myvar.author;desc = myvar.desc;LoadMovie(pic,picurl);}}//Cal the above functionLoadData();8Embed this<embed al ownetworking="al " pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" allowscriptaccess="always" align="middle" flashvars="uid=1" src="http://www.mywidgets.com/widget/mywidget.swf" height="230" type="application/x-shockwave-flash" bgcolor="#ffffff" width="194" name="mywidget" /></embed>9