Tuesday, December 1, 2009

Passing values to Flash using swfobject and capturing in Flash using AS3

Just like flashvars you can pass values to Flash even if you are using swfobject to display your flash. Below is the code to do that -

var so = new SWFObject("flash/465x535.swf", f_size, "385", "535", "9", "");
so.addVariable("file_path", "filename.jpg");

file_path is the variable which will be passed to Flash. Now to capture the value in Flash using AS3 the code will be as follows -

var filepath = root.loaderInfo.parameters.file_path;

Wednesday, October 7, 2009

Passing values between Flash and ASP.Net

Recently I had to integrate Flash and ASP.Net for Harley's test ride website because the website has been built in Flash and the data needs to be passed to asp.net which subsequently stores it in the MS-SQL database.

I had done it in the past and I was following the same approach but somehow the values which were returned from asp.net to flash were the complete code of the webpage whereas I was only passing "passed" or "invalid" to take some action in Flash depending upon the output from Asp.Net

After doing hours of search on the internet and R&D I finally found the problem and so to save time to my fellow developers I am posting the complete code below -

Flash Source Code:
var dataSender:LoadVars = new LoadVars();
var dataReceiver:LoadVars = new LoadVars();
dataReceiver.onLoad = function() {
if (dataReceiver.response == "invalid") {
} else if (dataReceiver.response == "passed") {
dataSender.sendAndLoad("bookatestride.aspx", dataReceiver, "GET");

C# Source Code:
public partial class bookatestride : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
if (....)

dataSender is calling the bookatestride.aspx page and passing one value in the variable called "email". In return aspx page is passing variable-value pair and that gets stored into the dataReceiver object.

I wasn't including "&" in the response.write and that was the reason I had wasted few hours trying to figure this out. So guys don't forget to include "&" in your Response.write

Thursday, June 25, 2009

Embed fonts in Flash

To embed the fonts for a dynamic text field in Flash select the text field and open the properties panel. In the properties panel you will be able to see a button called "Embed", click on that and it will ask you what all you want to embed such as Uppercase letters, Lowercase letters or Numerics.

Select the appropriate and press Ok and you are done.

Monday, May 25, 2009

JSON to Flash: YouTube Case Study

I had to implement a custom YouTube gadget in Flash. The term gadget does not refer to a specific gadget technology, such as Google Gadgets. YouTube Gadget refers only to small web applications, implemented in HTML or Flash, that are displayed within an iFrame on a YouTube brand channel.

And for that purpose I had to fetch the list of videos published by a particular YouTube user which can only be fetched in the form of JSON, RSS or Atom Feed. I decided to go with JSON, initially it was difficult for me to fetch the appropriate values I needed because the JSON returned by YouTube is quite complex in structured but finally I was able to sort it out.

JSON stands for JavaScript Object Notation and is mainly used to transmit such structured data over a network connection.

"firstName": "Atul",
"lastName": "Narang"

In my case the JSON has to be parsed from the following URL -

If you change the last parameter in the URL which is "author=designworxz" to "author=your youtube username" it will fetch list of videos published by you in the form of JSON.

The great community over at http://json.org have created a JSON parsing library for AS1, AS2 & AS3. But we will focus on Flash CS3 & AS2.0. You can find that parse class here: http://json.org/JSON.as

Below is the code to parse the JSON returned by YouTube -

import JSON;

var jsondata:LoadVars = new LoadVars();

jsondata.onLoad = function(success) {

if (success) {
trace("load successful");
var o:Object = json.parse(
var s:String = json.stringify(o);
} else {
trace("unable to load JSON data");


The variable "s" will display the complete JSON returned by YouTube in the Output window & then the only thing you have to do is to fetch the required String, Variables & Values from the returned JSON.

Good Luck!!

Monday, March 16, 2009

Flash CS3 UI Scrollbar

Guys, if you attach the UI Scrollbar component with Dynamic textbox in Flash where the text will be populated from XML or a Text file, the scrollbar won't work and resize automatically.

When I was working on one of my flash component where the data was being populated from XML, I assumed that the scrollbar will automatically adjust according to the amount of the data but nothing really happened.

So to make the scrollbar work after you have populated your dynamic textbox with the content you can type the following action to make the UIScrollbar work -

mc_scroll.maxScrollPosition = details.textHeight;

"mc_scroll" is the instance name of my scrollbar attached with the dynamic textbox & "details" is the name of my dynamic text box.

Friday, March 13, 2009

Playing multiple videos Dynamically

import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;

Create a connection object

var connection_nc:NetConnection = new NetConnection();

Create a NetStream object and pass the NetConnection object

var stream_ns:NetStream = new NetStream(connection_nc);
stream_ns.client = new Object();

One connection object can be used for more than one video stream.


myVideo is the name of my video object placed on the stage & video.flv is the video file which needs to be played. Now if you want to play another video you have to create a new NetStream object for each video otherwise it will not work. I spent 4 hours just to figure this out & kept trying different techniques to make my 4 different videos work with the same NetStream object. But unfortunately it is not possible.

So guys the trick is to create different NetStream object for each video & have fun.

Happy Streaming!!!

Wednesday, March 11, 2009

Flash XML parsing including HTML tags in the XML

If you want to parse the HTML tags within your XML, the XML document should look like below -

And in the Flash scripting if you have a Dynamic Textbox named dynTxt the code will be as follows -

dynTxt.htmlText = Variable holding your text data

Following are the tags supported by Flash while parsing XML-

Mask on Dynamic Textbox

I encountered a strange problem in Flash when I tried masking a dynamic text box and it didn't work. After doing lots of research on the internet I found out that if you mask a dynamic text box the text won't appear.

So to save time for the people trying to mask the dynamic text box here is the tip, click your text box in the properties panel click the Embed button and embed the fonts and your text will start appearing again.

Thursday, February 26, 2009

Online Rugby Game

I have recently finished an online Rugby Game which can be accessed at - www.303.com.au/projects/rugby/rugby.html

Hope you like it!

ReferenceError: Error #1065

I could not post any entries in the last few months because of my busy schedule & finally I got a chance to post this problem with AS3.0 while parsing XML.

While parsing XML I came through this error -

ReferenceError: Error #1065

which is kind of vague error, I could not find anything anything related to my code even after searching for hours. Finally I decided to jump into my XML & keep only few entries to test & it worked.

After sweating for hours I found the error in the XML because one of the node was missing. So guys if you are getting this error while parsing XML, jump into the XML and check your structure.