PDA

View Full Version : FlashVar Help


sabresfan
06-03-2008, 03:48 PM
Hi,

I'd like to use FlashVars so i can use the same swf multiple times for different images on a page.

to get an idea of what i'm trying to do you can go here: http://www.ronniesalvato.com/help to see what i have right now..the problem is that I'm currently using 3 different swfs. also, i will have the thumbnails open a small popup window with a full size image with a description etc. but i haven't created those pages yet so i just have it going to my current main page.

im pretty sure i know what the javascript should look like. for example the code for the first thumbnail could go something like this:


<script type="text/javascript">
var so = new SWFObject("assets/flash/project.swf", "video", "390", "100", "8", "#83C25D");
so.addVariable("imgName", "bird.jpg");
so.addVariable("imgLink", "bird");
so.write("bird");
</script>


the problem is that i have no idea how to insert the flashvar code into my flash file to get it to work. is there a kind soul that is willing to help me please?

this is my actionscript that i currently have.

import fl.transitions.*;
import fl.transitions.easing.*;

var borderSize = 10;
var imageRequest:URLRequest = new URLRequest("projects/bird.jpg");
var imageLoader:Loader = new Loader();
var movOriginal:MovieClip = new MovieClip();
var movOver:MovieClip = new MovieClip();
var home:MovieClip = this;


imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE,onLoadedImage);
imageLoader.load(new URLRequest("projects/bird.jpg"));

function onLoadedImage(e:Event):void {
//draw the borders, basically big rects behind the link image.
var g:Graphics = movOriginal.graphics;
g.clear();
g.beginFill(0x0C0C0C);
g.drawRect(0,0,imageLoader.width+borderSize*2,imag eLoader.height+borderSize*2);
g.endFill();
var g2:Graphics = movOver.graphics;

g2.clear();
g2.beginFill(0x83C15C);
g2.drawRect(0,0,imageLoader.width+borderSize*2,ima geLoader.height+borderSize*2);
g2.endFill();

//hide hover colour
movOver.alpha=0;
//make sure border is at the correct pos
movOver.x = movOriginal.x = imageLoader.x-borderSize;
movOver.y = movOriginal.y = imageLoader.y-borderSize;

//put items on the stage
home.addChild(movOriginal);
home.addChild(movOver);
home.addChild(imageLoader);
}

imageLoader.x = 10;
imageLoader.y = 10;
imageLoader.addEventListener(MouseEvent.CLICK, doSomething);
imageLoader.addEventListener(MouseEvent.MOUSE_OVER , mouseOverHandler);
imageLoader.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);

function doSomething(Event:MouseEvent):void {
var _link:URLRequest = new URLRequest("http://www.ronniesalvato.com");
navigateToURL(_link);
}

function mouseOverHandler(e:MouseEvent):void {
var myTween:Tween = new Tween( home.movOver, "alpha", Strong.easeOut, home.movOver.alpha, 1, 5, false);

}

function mouseOutHandler(e:MouseEvent):void {
var myTween:Tween = new Tween(home.movOver, "alpha", Strong.easeIn, home.movOver.alpha, 0, 5, false);

}

sabresfan
06-04-2008, 06:06 PM
this forum moves fast!

so does anyone have any ideas?

is it as easy as replacing the newURLRequest("projects/bird.jpg") code with some kind of FlashVar script?

is it much more complicated?

am i asking too many questions?

wvxvw
06-04-2008, 09:40 PM
trace(stage.loaderInfo.parameters.imgName);
trace(stage.loaderInfo.parameters.imgLink);
You might've searched the forum by the "FlashVars" keyword, this would positively shorten the time to get the answer ;)

sabresfan
06-05-2008, 03:51 PM
hey thanks for responding. this is probably a stupid question but where exactly do i insert that code? i can't seem to get it to work. i'm a total noob at this btw, so please bear with me. i know it gets annoying sometimes when someone doesn't even know the basics. thanks again for the help.

wvxvw
06-05-2008, 04:35 PM
In the very same place where you've written all your previous code... =\ (assuming it's main timeline)

sabresfan
06-05-2008, 05:33 PM
so lets say i delete the following code from my script:

var imageRequest:URLRequest = new URLRequest("projects/bird.jpg");

and

imageLoader.load(new URLRequest("projects/bird.jpg"));

are you saying that i can insert those 2 lines of code that you supplied me anywhere in my actionscript (doesn't matter if its at the beginning, middle or end) and it should work?

stompwampa
06-05-2008, 06:00 PM
Instead of using SWFObject, you can do this instead, with an HTML object tag:

<object type="application/x-shockwave-flash" data="myMovie.swf?variableName=myVariable" width="100" height="100">
<param name="movie" value=""myMovie.swf?variableName=myVariable"" />
</object>

The part you want is in BOLD

when yout put the ? after your file name, you're creating what is called a Query String. You can now create a variableName that can be anything you want, and then give a value to that variable.

So, if you want to give the source to an image, it would look like this:

<object type="application/x-shockwave-flash" data="myMovie.swf?source=directory/folder/image.jpg" width="100" height="100">
<param name="movie" value="myMovie.swf?source=directory/folder/image.jpg" />
</object>

Now, from inside Flash, you can use that code that wvxvw gave you:


trace(this.loaderInfo.parameters.source);


If you do that, Flash will trace out this:

directory/folder/image.jpg

So all you have to do is assign a variable equal to that query string:


var foo:Sring = new String();
foo = String(this.loaderInfo.parameters.source);


You can now use that variable for anything you need...it does not have to be a string either, it could be a Number or whatever...

Make sense??

tsquini
06-05-2008, 06:52 PM
I have my main class calling my XML class (XMLCentral).

In XMLCentral I have the code below.
I am not able to detect the loaderInfo.

public var XMLURL:String;

public function XMLCentral() {
var loader:URLLoader = new URLLoader();
configureListeners(loader);
XMLURL = this.loaderInfo.parameters.xmlLocation;

var request:URLRequest = new URLRequest(XMLURL);
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}


I am using the javascript flash embed code.
Can it be loaded though swfobject JS?

<script type="text/javascript" src="/assets/js/swfobject_source.js"></script>
</head>
<body id="home">
<div id="content">
<div id="flashcontent1">
</div>
<script type="text/javascript">
var so = new SWFObject("homepageRotate.swf", "TextLoad", "980", "384", "9", "#ffffff");
so.addVariable("xmlLocation", "slideLibrary.xml");
so.addParam("wmode", "transparent");
so.write("content");
</script>

</div>
</body>