Solved

pass query string to flash file

Posted on 2009-05-04
20
247 Views
Last Modified: 2013-11-11
hi, I am tring to pass a query string to my swf file, but it didnt work, I've tried to use the loaderInfor.parameters and the _root properties, but none of them are work, please help.

I am trying to pass a date to my counter
stop();

if (System.capabilities.playerType == "External" || System.capabilities.playerType == "StandAlone")

{

    this.dateOfReference = new Date(2009, 5, 25, 20);

} // end if
 

Stage.scaleMode = "noScale";

Stage.align = "TL";

if (this.dateOfReference == undefined)

{

    this.dateOfReference = new Date(2009, 5, 25, 20);

} // end if

_root.test = function ()

{

    var _l3 = Math.ceil(_root.dateOfReference.getTime() / 1000);

    var _l7 = new Date();

    var _l5 = Math.ceil(_l7.getTime() / 1000);

    if (_l3 > _l5)

    {

        var _l8 = _l3 - _l5;

        var _l6 = _root.getDayDiff(_l8);

        var _l4 = _root.getHourDiff(_l6[1]);

        var _l2 = _root.getMinDiff(_l4[1]);

        _root.days_txt.text = _root.formatNumberToDisplay(_l6[0]);

        _root.hours_txt.text = _root.formatNumberToDisplay(_l4[0]);

        _root.mins_txt.text = _root.formatNumberToDisplay(_l2[0]);

        _root.secs_txt.text = _root.formatNumberToDisplay(_l2[1]);

    }

    else

    {

        _root.days_txt.text = _root.formatNumberToDisplay(0);

        _root.hours_txt.text = _root.formatNumberToDisplay(0);

        _root.mins_txt.text = _root.formatNumberToDisplay(0);

        _root.secs_txt.text = _root.formatNumberToDisplay(0);

    } // end if

};

_root.getDayDiff = function (diffSec)

{

    var _l1 = new Number(86400);

    var _l2 = diffSec / _l1;

    _l2 = Math.floor(_l2);

    var _l3 = diffSec % _l1;

    return(new Array(_l2, _l3));

};

_root.getHourDiff = function (diffSec)

{

    var _l1 = new Number(3600);

    var _l2 = diffSec / _l1;

    _l2 = Math.floor(_l2);

    var _l3 = diffSec % _l1;

    return(new Array(_l2, _l3));

};

_root.getMinDiff = function (diffSec)

{

    var _l1 = new Number(60);

    var _l2 = diffSec / _l1;

    _l2 = Math.floor(_l2);

    var _l3 = diffSec % _l1;

    return(new Array(_l2, _l3));

};

_root.formatNumberToDisplay = function (numberValue)

{

    if (numberValue < 10)

    {

        return("0" + numberValue);

    }

    else

    {

        return(numberValue);

    } // end if

};

setInterval(this.test, 1000);

Open in new window

0
Comment
Question by:lyha_zm
  • 12
  • 7
20 Comments
 
LVL 22

Expert Comment

by:rascalpants
ID: 24298314
two things...

1. There is no reference to the loaderInfo method, and this IS what you would use to get something that is passed into your swf as a FlashVars or query string. when your code has that information in it, repost here and we will find the issue.

2.  Unless you are one of the worst programmers in the world and you insist on naming your variable and properties like an Obfuscator, this code was the result of a decompiled SWF.  Which I am sure is not something that you should be asking a question about based on the TOS and pirated software rules.  At the very least take the time to rename the variables to "hide" the fact that the code is taken from a decompiled SWF.


seriously though... if that IS the way you name your properties... God help anyone who has to work on this project next  :)


rp / Zone Adviser


 
// LoaderInfo example code

 

var loaderObj:Object = LoaderInfo(this.root.loaderInfo).parameters;

		

if ( loaderObj.theVariable )

{

  myVariable = loaderObj.theVariable;

}

else

{

  // does not exist, so set manually

  myVariable = "rascalpants rocks!";

}

Open in new window

0
 

Author Comment

by:lyha_zm
ID: 24298651
Thanks for the these non- suggestions,
first of all, you should ask me if this is from a decompilier or not, please dont ASSUME it's from a decompiler, and it is not.
second, if I am a expert in flash I wouldnt come here and ask questions.
third, I dont think the naming convention is a problem in this case, I didnt see any difference between mine and yours,
a suggestion for you,  I think you should be focus on more what my problem was, not the other things, and it is nothing for you to worried about who will be the next one to answer my questions.
by the way, I also dont except you can answer this question.
0
 

Author Comment

by:lyha_zm
ID: 24299584
Hi, rascalpants
You were right about flash is not my strongest, I am new to flash, these code are not mine, I got it form somewher else but the decomplier, I am trying to modify it, I would like to pass a date from query string to the flash. and as I said before, it is a countdowm clock.
this is what I've tried, in the begining I wasnt sure if it is AS3 or AS1/AS2,
so I tried AC3 first, use the loaderInfo.parameter, I didnt get any result back, then I tried the way under AS1/AS2, using the _root, _level0, it still doesnt work.
I also tried your way too, still didnt show anything, I wish I could attach the fla file, so you could try it out

if (System.capabilities.playerType == "External" || System.capabilities.playerType == "StandAlone")

{

    this.dateOfReference = new Date(_root.endyear, _root.endmonth, _root.endday);

} // end if

 

Stage.scaleMode = "noScale";

Stage.align = "TL";

if (this.dateOfReference == undefined)

{

    this.dateOfReference = new Date((_root.endyear, _root.endmonth, _root.endday);

} // end if

--------------------------------------------------------------------
 
 

if (System.capabilities.playerType == "External" || System.capabilities.playerType == "StandAlone")

{

    this.dateOfReference = new Date(loaderInfo.parameter.endyear, loaderInfo.parameter.endmonth, loaderInfo.parameter.endday);

} // end if

 

Stage.scaleMode = "noScale";

Stage.align = "TL";

if (this.dateOfReference == undefined)

{

    this.dateOfReference = new Date(loaderInfo.parameter.endyear, loaderInfo.parameter.endmonth, loaderInfo.parameter.endday);

} // end if

Open in new window

0
 

Author Comment

by:lyha_zm
ID: 24299607
this is the code in HTML
	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="964" height="96" id="chrono" align="middle">

	<param name="allowScriptAccess" value="sameDomain" />

	<param name="allowFullScreen" value="false" />

	<param name="movie" value="chrono.swf?endyear=2009" />

<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />

	<embed src="chrono.swf?endyear=2009" quality="high" bgcolor="#ffffff" width="964" height="96" name="chrono" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />

	</object>

Open in new window

0
 

Author Comment

by:lyha_zm
ID: 24299614
sorry this is the right one
	<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="964" height="96" id="chrono" align="middle">

	<param name="allowScriptAccess" value="sameDomain" />

	<param name="allowFullScreen" value="false" />

	<param name="movie" value="chrono.swf?endyear=2009&endmonth=5&endday=25" />

<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />

	<embed src="chrono.swf?endyear=2009&endmonth=5&endday=25" quality="high" bgcolor="#ffffff" width="964" height="96" name="chrono" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />

	</object>

Open in new window

0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24299668

Technically, you should only need to use the code I gave you, and nothing else, as long as you are using a browser to run this, and not the IDE.  I tested my code again, and it works fine.

what you would want to do is this for a new date to come in...


var passedData:Object = loaderInfo.parameter;
this.dateOfReference = new Date( int( passedData.endyear ), int( passedData.endmonth ), int( passedData.endday ) );


but if this is not run from a browser, then it will not work... the loaderInfo object will be null.


so you are running this from within a browser?

rp / ZA

0
 

Author Comment

by:lyha_zm
ID: 24299703
yes, I did run it in a browser
0
 

Author Comment

by:lyha_zm
ID: 24299706
is there a way I can test it?
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24299805


here is what i put in my first frame...


// LoaderInfo example code
var myVariable:String;
var loaderObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
     
// endyear=2009&endmonth=5&endday=25       
      
if ( loaderObj.endyear )
{
  myVariable = loaderObj.endyear;
}
else
{
  // does not exist, so set manually
  myVariable = "rascalpants rocks!";
}


trace( myVariable );



and in my HTML here is what i had...


<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>loaderInfoTest</title>
</head>
<body bgcolor="#ffffff">

<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="chrono" align="middle">
   <param name="allowScriptAccess" value="sameDomain" />
   <param name="allowFullScreen" value="false" />
   <param name="movie" value="loaderInfoTest.swf?endyear=2009&endmonth=5&endday=25" />
   <param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />
  <embed src="loaderInfoTest.swf?endyear=2009&endmonth=5&endday=25" quality="high" bgcolor="#ffffff" width="550" height="400" name="chrono" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
</object>

</body>
</html>




and in the IDE... it traces out to "rascalpants rocks!"  but in the browser (using FlashTracer for FF) it traces out 2009.


now all you would have to do is turn that into an int and you would be ready to go...



rp / ZA
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:lyha_zm
ID: 24305828
sadly, it still doesnt work
0
 

Author Comment

by:lyha_zm
ID: 24305833
by the way, I am using CS4
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24306001

try to start from scratch with this, and not implement into your current project.   all you need to do is past the code above into the first frame and compile the SWF.

then in a text editor, copy and past the other code into that and rename it...  

then run it locally...  it should work just fine... as it has on my machine.

and it should not matter what version of Flash you are using, cause the code the exports are not defendant on that.


rp / ZA

0
 

Author Comment

by:lyha_zm
ID: 24306248
that's what I did, I start from scratch, I create a dynamic text and used your code, the result is I got this line: rascalpants rocks, that means it still didnt find the parameters/ right? what should I do next?
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24306670

from the Flash software, you will get the default "rascalpants rocks"...  but if you run this in a browser, it will give you what ever is passed in as that variable in the Query String.

loaderInfoTest.swf?endyear=2009


endyear should be passed in and then traced out or displayed in your dynamic text box...

I am not sure what more to do...  It works perfectly on my end.


rp / za  
0
 

Author Comment

by:lyha_zm
ID: 24306690
yeah, I understand, I get undefind if I just let to display the result. is that give you something for to think?
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24306732

this means that you are passing in a value to the dynamic text box that is not the same as what is being loaded in.

paste all of your actionscript here, and also double check what you have named your dynamic text box and let me know.


rp / ZA
0
 

Author Comment

by:lyha_zm
ID: 24306953
see attached file
flash.doc
0
 
LVL 22

Accepted Solution

by:
rascalpants earned 500 total points
ID: 24307138
Okay, the issue is not in your Flash code, except for the fact that you are using a String() method for no reason, because myVariable is already datatyped as a string.

The problem is that you are not using the same code I am in your HTML...  you are using the AC_FL_RunContent  javascript...  Either use my exact code, so update your html to pass in FlashVars.... that or even better, use SWFObject and pass in the parameters that way...


find the param for movie in the AC_FL_RunContent code:


<param name="movie" value="loaderInfoTest.swf?endyear=2009" />


and also do it in the embed as well...


<embed src="loaderInfoTest.swf?endyear=2009" ....



or you could always use FlashVars instead of the Query String...    

<param name="FlashVars" value="endyear=2009" />



that should work...


rp / ZA



0
 

Author Comment

by:lyha_zm
ID: 24308688
you are awosome!!!! it's working now :) thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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 select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now