?
Solved

url variable split

Posted on 2006-05-09
10
Medium Priority
?
279 Views
Last Modified: 2010-04-03
I am trying to split a url and asign to variable in flash...lets say that i have 3 text boxes...and get the var values from url and display it....

C:\Documents and Settings\admin\Desktop\BTS\navigation.html?var1=sub&var2=list&var3=42

I got this code from other experts exchange answer...but, couldn't able to use it...can u please explain me step by step...

String.prototype.change = function( o , n ){
    for ( var i = 0 , ret = this ; i < o.length ; i++ )
        ret = ret.split( o.charAt( i ) ).join( n.charAt( i ) );
    return( ret );
}

_global.queryString = function( variavel ){
    var linha = __querystring.split( "?" )[ 1 ].split( "&" );

    for ( var i = 0 ; i < linha.length ; i++ ){
        var partes = linha[ i ].split( "=" );
        if ( partes[ 0 ].toLowerCase() == variavel.toLowerCase() ){
            var valor = partes[ 1 ].split( "+" ).join( " " );
            return( valor = isNaN( valor.change( "-,." ) ) ? valor : Number( valor ) );
            break;
        }
    }
}

_root.onEnterFrame = function(){
    if ( __querystring != null ){
        var tf = _root.field
        tf.text += "Name : " + queryString( "Name" ) + newline;
        tf.text += "Age  : " + queryString( "Age"  ) + newline;
        delete this.onEnterFrame;
    }
}



///html code

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <script>
        function QueryString(){
            document.Neto.SetVariable( "_global.__querystring" , window.location );
        }
    </script>
</head>

<body onload="QueryString()">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="navigation" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="navigation.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="navigation.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="navigation" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>

</html>
0
Comment
Question by:SubhaBabu
  • 4
  • 4
  • 2
10 Comments
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16644829
Hi,

Here I have done a sample for you.
download it here:
http://download.yousendit.com/1BC0561022DA248F


Rgds
Aneesh
0
 
LVL 2

Expert Comment

by:oddhours
ID: 16645155
Here’s a good source: http://www.permadi.com/tutorial/flashQueryString/index2.html

First you need to pass the query string of your web page to your swf file.

There are several ways of doing this.

JavaScript:


<HTML><HEAD><TITLE>Example</TITLE></HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
document.write(
  '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"\n'+
  ' codebase="...see source...\n'+
  ' WIDTH="250" HEIGHT="250" id="flaMovie">\n'+
  ' <PARAM NAME=movie VALUE="flaMovie3.swf'+document.location.search+'">\n'+
  ' <PARAM NAME=quality VALUE=high>\n'+
  ' <PARAM NAME=bgcolor VALUE=#FFFFFF>\n'+
  ' <EMBED src="flaMovie3.swf'+document.location.search+'"\n'+
  '    quality=high bgcolor=#FFFFFF  WIDTH="250" HEIGHT="250" NAME="flaMovie1"\n'+
  '    TYPE="application/x-shockwave-flash"\n'+
  '    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>\n'+  
  '</OBJECT>');
//-->
</SCRIPT>
</BODY>
</HTML>


ASP:

<HTML>
<HEAD><TITLE>Example</TITLE></HEAD>
<BODY>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  codebase="http://macromedia.com/cabs/swflash.cab#version=6,0,0,0"
  ID=flaMovie WIDTH=250 HEIGHT=250>
  <PARAM NAME=movie
    VALUE="flaMovie3.swf?<%=Request.QueryString%>">
  <PARAM NAME=quality VALUE=medium>
  <PARAM NAME=bgcolor VALUE=#99CC33>
  <EMBED src="flaMovie3.swf?<%=Request.QueryString%>"
    bgcolor=#99CC33 WIDTH=250 HEIGHT=250
    TYPE="application/x-shockwave-flash">
  </EMBED>
</OBJECT>
</BODY>
</HTML>


PHP:

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  codebase="http://macromedia.com/cabs/swflash.cab#version=6,0,0,0"
  ID=flaMovie WIDTH=250 HEIGHT=250>
  <PARAM NAME=movie VALUE="flaMovie3.swf?<?php echo($QUERY_STRING);?>">
  <PARAM NAME=quality VALUE=medium>
  <PARAM NAME=bgcolor VALUE=#99CC33>
  <EMBED src="flaMovie3.swf?<?php echo($QUERY_STRING);?>"
    bgcolor=#99CC33 WIDTH=250 HEIGHT=250
    TYPE="application/x-shockwave-flash">
  </EMBED>
</OBJECT>


Then inside your FLA, each of the variables would be accessible as a string…

If you used a link to the site: http://www.myurl.com/mySWFpageHere.html?var1=sub&var2=list&var3=42

It’s as if on Frame 1 on the main timeline in your flash file you had declared:
var1=”sub”;
var2=”list”;
var3=”42”;

They would be immediately accessible. i.e.

trace(var1);
trace(var2);
trace(var3);

download an example: http://www.mytempdir.com/654931

0
 
LVL 2

Author Comment

by:SubhaBabu
ID: 16648402
Aneesh, I took ur sample code... and added the hard code url into this.url and ran the code...as i expected it gave me empty boxes and when i enter the value in the url box and enter ...it gave me a error message "Check the spelling or try again"...my url is C:\Documents and Settings\admin\Desktop\Flash_tutorial\splitting_variable_sample\splitting_variable_sample.html?var1=babb&var2=listy&var3=544


can i able to test locally?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16651006
my sample shows that how a complete URL with querystring can be splitted and variables value can be used.

i have used a dummy complete URL with querystring,, and variables have been read and displayed in input boxes..

you need to set the "completeURL" variable with the hard coded URL

----------
completeURL = "C:\Documents and Settings\admin\Desktop\BTS\navigation.html?var1=sub&var2=list&var3=42";
var_arr = completeURL.split("?")[1].split("&");
trace(var_arr);
for (i=0; i<var_arr.length; i++)
{
      tmp = var_arr[i].split("=");
      this[tmp[0]].text = tmp[1];
}
-----------
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16651021
this.url always return only swf complete path, it will not return the html path with querystring..
0
 
LVL 2

Author Comment

by:SubhaBabu
ID: 16658170
i want the ability to dynamically load the url...i cannot hard code the url...anyway...atleast it shoul return a empty box in that case,right....but y i am getting "check your spelling error on IE" even before i get into the swf part?
0
 
LVL 2

Author Comment

by:SubhaBabu
ID: 16658577
oddhours, I tried your solution...it does work...but, how do i split the variables from the url....

I can able to get ?var1=sub&var2=300&var3=250....But how do i get flash var1 = sub and flash var2 = 300 and flash var3=250...
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16660441

Let's assume you have received the all variables in the flash as single string in a variable "completeURL".. as following

completeURL = "?var1=sub&var2=300&var3=250";

now following code will split all variables and make them available for use in flash
--------------
var_arr = completeURL.split("?")[1].split("&");
for (i=0; i<var_arr.length; i++)
{
     tmp = var_arr[i].split("=");
     this[tmp[0]]= tmp[1];
}
trace(var1);
trace(var2);
trace(var3);
---------------

after running above code, you can use any variable with its names... all of the variables have been splited and available on timeline.

Rgds
Aneesh
0
 
LVL 2

Accepted Solution

by:
oddhours earned 1000 total points
ID: 16664920
Based on the page's url, "sample.html?var1=babb&var2=listy&var3=544" it is possible to pass the values of var1, var2 and var3 to the flash movie directly without sending the entire string and parsing it inside the fla, (although if you ever needed to, Aneesh's code does it very elegantly).

Perhaps your problem was the result of sloppy coding on my part. Sorry for the poor examples above.

To pass the variables contained in the page's query string directly to a flash movie called "MyFlash.swf" in your page, use the following syntax:

Find the flash movie's object tag and anywhere you see "MyFlash.swf" replace it with:
----------
ASP:

"MyFlash.swf?<%=Request.QueryString%>"
----------
PHP:

"MyFlash.swf?<?php if (isset($_SERVER['QUERY_STRING'])) echo $_SERVER['QUERY_STRING'];?>"
----------

To embed the flash swf and pass the query string using JavaScript you would use something like:

<SCRIPT LANGUAGE="JavaScript">
<!--
document.write(
  ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" \n'+
  ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"\n'+
  ' width="250" height="250" id="MyFlash" align="middle">\n'+

//Here is the PARAM Tag change...
  ' <PARAM NAME=movie VALUE="MyFlash.swf'+location.search+'">\n'+
  ' <PARAM NAME=quality VALUE=high>\n'+
  ' <PARAM NAME=bgcolor VALUE=#FFFFFF>\n'+

//Here is the EMBED Tag change...
  ' <EMBED src="MyFlash.swf'+location.search+'"\n'+
  ' quality=high bgcolor=#FFFFFF  WIDTH="250" HEIGHT="250" NAME="MyFlash"\n'+
  ' TYPE="application/x-shockwave-flash"\n'+
  ' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');
//-->
</SCRIPT>


Now you should be able to access those variables in the root timeline of MyFlash.swf.
For example, if you want to assign the value of var1 to a text instance named textBox1_txt, you could either
  1. set textBox1_txt's property type to Dynamic and enter var1 in the "Var:" input box. Or,
  2. assign the value of var1 to the text directly. ie.   textBox1_txt.text = var1;

This what you're after?
0
 
LVL 2

Author Comment

by:SubhaBabu
ID: 16690860
Oddhours,
I thought thats what I need to do...but it didn't work...Please check this file attached and debug it if possible or give me a solution...

http://www.yousendit.com/transfer.php?action=download&ufid=408DF4452BD6ABAD 

Aneesh, Please take a moment to go through my files.

thanks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question