PDA

View Full Version : Passing dynamic content to the next frame.



datzun
October 23rd, 2008, 11:29 AM
Morning everyone.

I have a flash banner that I'm creating that pulls dynamic content from a database. It's basically a URLRequest to a PHP file, the PHP file calls the database, returns the values, and brings them into Flash. Using URLVariables, I split it out and put certain values into certain textfields. Pretty basic stuff.

The problem I'm having is this banner runs over and over again (as I want it to). In doing so, it makes the call to the database on each iteration (which I don't want to). I'm trying to find a way to store the variables I pull in and pass them on. At first I was hoping to just get to the end of the clip and do a gotoAndPlay(2) to get it to loop and not include the database call. However, doing so gives me empty fields. This made me realize that anytime I reference the data after the first frame, I get null results.

Here's my code snippet:


var req:URLRequest = new URLRequest(theURL);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete);

loader.load(req);

function onComplete(event:Event):void{
var vars:URLVariables = new URLVariables(event.target.data);

price_mc.price_txt.text = vars.data1;
cb_mc.cb_txt.text = vars.data1;
tcb_mc.tcb_txt.text = vars.data1;

}


Any thoughts on how I can get the dynamic data in these text fields passed on without doing the database call each iteration?

Thanks.

scottc
October 23rd, 2008, 12:27 PM
If your using frames...
Make a new layer, with 1 keyframe, and enough non-key frames after to fill your movie.

Then put all your code on that layer. (not 100% sure that i'll work, but worth a try.)



if(asdf = null || asdf = undefined || asdf = ""){
//set adsf variable
}


Some code like that could help you set your variable once.

datzun
October 23rd, 2008, 12:33 PM
All my actionscript coding already is in it's own layer. :(

If I insert a new keyframe after the keyframe that makes my database call and try to reference the dynamic text I populated in my text fields, I get null values. However, I can reference any static variable just fine...

scottc
October 23rd, 2008, 12:55 PM
What you could do, is place all your animations inside a movieclip. Then only have only 1 frame on your main timeline...

give your movieclip an instance name...



my_mc.mytext.text = "howdy from main timeline";
my_mc.stop();
my_mc.gotoAndPlay(1);
my_mc.makemefood("cheese burger");
//etc



Tip:
Select all the animation frames in the timeline -> rightclick -> copy/cut -> go in new mc -> click timeline -> right click -> paste.

datzun
October 23rd, 2008, 01:42 PM
What you could do, is place all your animations inside a movieclip. Then only have only 1 frame on your main timeline...

give your movieclip an instance name...



my_mc.mytext.text = "howdy from main timeline";
my_mc.stop();
my_mc.gotoAndPlay(1);
my_mc.makemefood("cheese burger");
//etc

Tip:
Select all the animation frames in the timeline -> rightclick -> copy/cut -> go in new mc -> click timeline -> right click -> paste.

Scott, I think I love you. I took your idea and edited it a bit to get things working. Thanks a bunch!