PDA

Click to See Complete Forum and Search --> : Passing variables between 2 .swf files on 2 HTML pages



legendkiller
04-13-2007, 05:58 PM
Hi there,

had a problem passing a couple of variables across 2 .swf files on 2 HTML files for a while now. I tried posting in another part of the forum but they couldnt help so I was referred here.

http://board.flashkit.com/board/showthread.php?p=3848519#post3848519

Anybody know the simpleset way I can do this because im not to good with CSS/HTML etc..

Thanks in advance

LK

1stbite
04-14-2007, 06:54 AM
opps double posted somehow...

1stbite
04-14-2007, 07:03 AM
pass the variable (urlVar) by URL in your swf:


// start button function
butt_1.onRelease = function() {
var gotoURL = "targetPage.html?urlVar="+urlVar;
getURL(gotoURL, "_self");
};
//end button function


in head element of html add follwing javascript function:


<script language="javascript">
function gup( name ) {
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var tmpURL = window.location.href;
var results = regex.exec( tmpURL );
if( results == null )
return "";
else
return results[1];
}
var urlVar = gup('urlVar');
</script>


then re-write your movie param and embed with javascript to include the varaible to load into you movie:


<script language="javascript">document.write('<param name="movie" value="movieOnSecondPage.swf?urlVar='+urlVar+'">'

and


<script language="javascript">document.write('<embed src="movieOnSecondPage.swf?urlVar='+urlVar+'" quality="high" bgcolor="#ffffff" width="550" height="400" name="mov_2" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');</script>


then you access the variable within the movie as 'urlVar' (or what ever name you use)

you will need to edit the param and embed to match your movie of course...

hope its of help.

legendkiller
04-15-2007, 03:04 PM
Right ive had a go at it but no luck.

Few questions on your code:

Part 1 code to be placed on button click or frame 1?

The second part of code, is this to be placed in the sending html's page or the recieving?

The third and fourth part of code same question, what page will all the param and embed code be deleted and re-wrote(sending html page or recieving?)

Thank you

1stbite
04-15-2007, 04:29 PM
Right ive had a go at it but no luck.

Are you testing locally or on a server? locally it woun't work as the url varaibles don't get passed to next page, put the files online and the variables get passed and it all works.


Part 1 code to be placed on button click or frame 1?

Frame 1
also make sure your button on the stage has the instance name of butt_1 so the function can target it.


The second part of code, is this to be placed in the sending html's page or the recieving?

Receiving page, this it the javascript function that will pull the url variable from the URL address so you can use it in the flash html mark-up.


The third and fourth part of code same question, what page will all the param and embed code be deleted and re-wrote(sending html page or recieving?)

Also receiving page, only delete two lines of mark-up in the flash code, the <param name="movie"... and all of the embed element and its attributes and replace both with the script element equivialants.



I've uploaded a mx2004 format .zip of the fla's, swf's and the html's for this solution, remember that if you publish the .fla files it will over right the javascript code in the .html files so be warned... and remember the files need to be online to allow the varaibles to send from one page to the next.

link to .zip files (http://www.yourfilehost.com/media.php?cat=other&file=passVars.zip)

legendkiller
04-15-2007, 05:06 PM
Thanks for the help but again no luck.

Im having the same problem with your files as I am with mine. The page wont load.

http://www.gregharrison.co.uk/variables/mov_1.html

Also, I cannot open the .fla files you provided. Unexpected file format is the error. Shouldnt be a problem considering I am using MX 04.

1stbite
04-16-2007, 06:05 PM
Sorry I knocked up the example on a Mac and only tested it with FireFox and Safari which both don't have a problem with it, on testing on a windows machine with IE 6 or 7 I see the flash file is not getting recognised and even detected as Java in IE 7 :s

Maybe writing all the flash in javascript will sort it (seemed to work ok here)

OK try replacing the html code with this on both files: (just change file names of swf respectively)



<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>mov_2</title>
<script language="javascript">
function gup( name ) {
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var tmpURL = window.location.href;
var results = regex.exec( tmpURL );
if( results == null )
return "";
else
return results[1];
}
var urlVar = gup('urlVar');
</script>
</head>
<body bgcolor="#ffffff">
<script language="javascript">
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="550" height="400" id="mov_2" align="middle">');
document.write('<param name="allowScriptAccess" value="sameDomain" />');
document.write('<param name="movie" value="mov_2.swf?urlVar='+urlVar+'">');
document.write('<param name="quality" value="high" />');
document.write('<param name="bgcolor" value="#ffffff" />');
document.write('<embed src="mov_2.swf?urlVar='+urlVar+'" quality="high" bgcolor="#ffffff" width="550" height="400" name="mov_2" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
</script>
</body>
</html>

(NOTE: all document.write('***HTML***'); should be on one line, the above forum code view breaks the code so if you cut and paste the lines will be broken so you have to fix them.

I don't understand whats up with the .fla's? check your PM's

theWilfen
05-02-2007, 05:08 PM
Looks good.

I need to do a similar thing, but, but passing a variable from one .swf to another in different cells on the same html page.

One side is a navigation, and the other side is the viewing area...I had to separate them to get around a _root code problem, otherwise I would have just done the whole thing in Flash.

So, I need to pass avariavble from the navigation .swf to HTML so it knows which html page to load in the right-hand content area.

Any ideas?

theWilfen
05-04-2007, 12:48 PM
Looks good.

I need to do a similar thing, but, but passing a variable from one .swf to another in different cells on the same html page.

One side is a navigation, and the other side is the viewing area...I had to separate them to get around a _root code problem, otherwise I would have just done the whole thing in Flash.

So, I need to pass avariavble from the navigation .swf to HTML so it knows which html page to load in the right-hand content area.

Any ideas?

Actually, I was able to avoid HTML and JS entirely by using the 'content' .swf's rootlock property, thus keeping all downstream references to _root locked to this .swf, as opposed to the MetaPlayer...easy solution, and now I don't have to deal with using js to configure a custom window to allow for more real estate (damned toolbars!).


w.

mneil
06-27-2007, 07:16 PM
I know this post is a little older and you've got the solution to your problem theWilfen but you should look into local connection() next time that you need to do something like that.