We help IT Professionals succeed at work.

pass query string to flash file

lyha_zm
lyha_zm asked
on
282 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

Comment
Watch Question

CERTIFIED EXPERT

Commented:
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

Author

Commented:
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.

Author

Commented:
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

Author

Commented:
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

Author

Commented:
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

CERTIFIED EXPERT

Commented:

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

Author

Commented:
yes, I did run it in a browser

Author

Commented:
is there a way I can test it?
CERTIFIED EXPERT

Commented:


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

Author

Commented:
sadly, it still doesnt work

Author

Commented:
by the way, I am using CS4
CERTIFIED EXPERT

Commented:

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

Author

Commented:
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?
CERTIFIED EXPERT

Commented:

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  

Author

Commented:
yeah, I understand, I get undefind if I just let to display the result. is that give you something for to think?
CERTIFIED EXPERT

Commented:

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

Author

Commented:
see attached file
flash.doc
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
you are awosome!!!! it's working now :) thanks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.