View Full Version : How to use flashvars with AS3?
jszpila
April 9th, 2008, 03:39 PM
Hello All,
I've poked around and I know this is really simple, but I can't find anything that seems to work. I'm trying to do the following:
trace(root.loaderInfo.parameters.myvar);With the following embed code:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
width="550"
height="400"
id="test"
align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="test.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="FlashVars" value="myvar=test" />
<embed src="test.swf"
quality="high"
bgcolor="#ffffff"
width="550"
height="400"
name="test"
align="middle"
allowScriptAccess="always"
allowFullScreen="false"
type="application/x-shockwave-flash"
FlashVars="myvar=test"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
But it keeps returning undefined. What am I doing wrong here?
Thanks in advance!
wvxvw
April 10th, 2008, 03:19 AM
The code should work, but try checking for the vars a bit after the flash was loaded. E.g. set timer to check if there's such a variable in .params. Once it's defined - turn the timer off =)
Qbe
April 10th, 2008, 04:11 AM
Try SWFObject it worked for me, when I hade problem with Flashvars.
http://blog.deconcept.com/swfobject/
Oshii
April 10th, 2008, 06:57 AM
You need to test the code in a web browser because the swf won't find the html file containing the flashvars if you just test the movie.
You're probably doing everything right codewise.. here's an example.. run the html file to see the flashvars..
jszpila
April 10th, 2008, 10:17 AM
Thanks for your help, everyone. I went through a few different methods and discovered the solution was a little embarrasing - I was looking through Oshii's source and saw that I was forgetting to put the flash vars paramater in the runactivecontent script call like so:
'flashVars', 'dosomething=true&mode=false&numpics=100'
Once I put those in there, it worked like a charm.
Thanks again!
someduder
May 28th, 2008, 06:24 PM
I need to deliver a simple (read: "single file") for a client to deploy and maintain. Is it possible to pull the logic into the timeline in AS3 rather than use an external class? All of my experiments are coming up empty.
(Just for amusement I have also tried moving all the rest of my logic from frame 1 to the external file but it causes Flash to throw many "1120: Access fo undefined property" errors. Changed function defs to public function defs, but no luck.) TIA!
Alex Lexcuk
May 29th, 2008, 01:56 AM
http://dnadillo.dn.ua/mur_gallery/params.txt
//first frame code
import flash.events.*;
import flash.net.*;
import flash.display.*;
import flash.net.URLRequest;
//import flash.display.SimpleButton;
// out_text.my_caption_txt.text="JJJJJJ";
// out_text.x=100;
var my_gallery_container:Sprite = new Sprite();
my_gallery_container.x=10;
my_gallery_container.y=10;
addChild(my_gallery_container);
var my_source:String = "http://dnadillo.dn.ua/params.txt";
var my_array:Array = new Array;//name image
var my_sprite_arr:Array= new Array;//array image
var count_images:Number=1;//counter loading image
var dataFormat:String = URLLoaderDataFormat.TEXT;
var my_string:String=new String;
var go:Number=0;//trigger if loading
var i,j:Number;
var loader:URLLoader = new URLLoader();
loader.dataFormat = dataFormat;
var request:URLRequest = new URLRequest(my_source);
try {
loader.load(request);
} catch (error:Error) {
trace("Error loading requested document: " + my_source);
}
function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler (text): " + loader.data);
my_after_load_text();
}
loader.addEventListener(Event.COMPLETE, completeHandler);
function my_after_load_text()
{
my_string=loader.data;
translate_line(my_string);//в массив my_array[i]
my_txt.text="";
for (i=1;i<my_array.length;i++)
my_txt.text=my_txt.text+"\n"+my_array[0]+my_array[i];
}
//break text file form string array
function translate_line(str_line)
{
var my_enter:String; //
my_array = str_line.split("\n");//break at simbol \n
for (var i = 0; i<my_array.length; i++)
{
my_enter=my_array[i];//строка равна елементу массива
my_array[i]=my_enter.substring(0,my_enter.length-1);//remove enter at end of line
trace(my_array[i]+" "+my_enter.length);//покажем, что натворили
go=1;//load = true
}
}
//end break text file form string line
http://dnadillo.dn.ua/mur_gallery/page_0.html
http://dnadillo.dn.ua/mur_gallery/mur_gallery.rar
OR PHP MODEL
http://dnadillo.dn.ua/images/imag/GaleryScoresText.php
http://dnadillo.dn.ua/mur_gallery/php/AC3_PHP.swf
http://dnadillo.dn.ua/mur_gallery/php/GaleryScoresText.txt
http://dnadillo.dn.ua/mur_gallery/php/mur_galery_AC3_PHP.rar
Mega embed swf
http://www.swffix.org/swfobject/generator/
someduder
May 29th, 2008, 01:30 PM
Thanks, Alex. I have bookmarked all that good info and am sure will be useful in the future.
But my current need is to pass variables via the object/embed/AC_RunActiveContent HTML, which will be dynamically generated. I like the way you have achieved the inclusion of variables in a flat external file, but it still leaves me with another external file rather than a single FLA.
So I'm looking for a way to implement the original solution presented in this thread, in frame 1 without using an external .as file. Any and all advice will be greatly appreciated!
wvxvw
May 29th, 2008, 02:00 PM
simply change root to stage here...
trace(root.loaderInfo.parameters.myvar);
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.