Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Get URL Variable

Community Beginner ,
Jul 09, 2008 Jul 09, 2008
I have two relevant pages -

The first presents a list of choices in HTML, and allows the user to select one. Upon selection, a variable is passed to the URL for the second page. (?installer=foo)

The second page contains the Flash movie. How may I grab the variable from the currently loaded page?

Thanks!
3cl3c71k0r
TOPICS
ActionScript
840
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jul 11, 2008 Jul 11, 2008
Thanks for your help, David. After testing your file, I discovered that the method worked on my local machine, my own personal hosting account, and NOT my business' hosting account. We're working right now to figure out why. I'm guessing it has something to do with our content management system. Kinda sucks to try fixing your alignment when one tire is flat.

Thanks again for your help!
Translate
LEGEND ,
Jul 09, 2008 Jul 09, 2008
If you're passing that variable to the URL of the second page, you can
use JavaScript's Location object to grab the data from the question mark
forward.

http://www.comptechdoc.org/independent/web/cgi/javamanual/javalocation.html

Use String manipulation to rip the data you want, then pass those values
into FlashVars or a query string on the SWF file reference itself. In
ActionScript, those values will show up in the parameters property of the
LoaderInfo instance associated with the root. In other words, given that
your variable is installer ...

root.loaderInfo.parameters.installer

... from inside Flash. To get that data *to* Flash, use FlashVars ...

http://www.permadi.com/tutorial/flashVars/index.html

... or duplicate the query string on the SWF file reference in the HTML.
Using something like Geoff Stearns' SWFObject helps tremendously, because
you'll need to dynamically pass in these values anyway. If you're using
JavaScript, I can't think of a better embed script than SWFObject. Of
course, you could just as soon use PHP, to append the values as a query
string or FlashVars.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 10, 2008 Jul 10, 2008
Thanks for the reply! I've checked out that link and a few others. Still no luck. This seems to be a sticky topic for a lot of folks. Here's the simplified version I have right now:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2008 Jul 10, 2008
eclectikor,

> Thanks for the reply! I've checked out that link and a few others.
> Still no luck. This seems to be a sticky topic for a lot of folks.

FlashVars are a useful tool, and they were a tad easier to use in prior
to AS3 ... simply because the passed-in variables were available, like
magic, as main timeline variables. It's not much harder in AS3, though,
once you see what's going on.

> simplified version I have right now:
>
> html:
>
> <script language="javascript">
> // code snipped ...
> 'flashvars', 'instID=kyle',

Good, there's your FlashVars variable, as passed to the JavaScript. Not
sure if that needs to be FlashVars as opposed to flashvars, but it may not
make a difference.

> // additional code snipped ...
> <param name="flashvars" value="instID=kyle" />
> // snipped again ...
> <embed src="/flash/fcGalleryPreloader.swf" quality="high"
> bgcolor="##000000" flashvars="instID=kyle" ...

Okay, good. And there are your FlashVars again, passed directly to the
SWF (in case this user doesn't have JavaScript enabled (note this part is
inside a <noscript> tag). So far, so good.

> AS3:
>
> var extVars:Object = LoaderInfo(this.root.loaderInfo).parameters;
> instID_txt.text = String(extVars["instID"]);

At this point, you've lost me, but it shouldn't be hard to nail down. I
see you've got a text field with the instance name instID_txt, and you'd
like to set its text property. To do that, just reference the instID
variable in the parameters property of that LoaderInfo instance:

instID_txt.text = root.loaderInfo.parameters.instID;


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 10, 2008 Jul 10, 2008
I'm afraid that doesn't work. I've tried about 50 permutations like this, but in every case Flash tells me that the value is null.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2008 Jul 10, 2008
eclectikor,

> I'm afraid that doesn't work. I've tried about 50 permutations
> like this, but in every case Flash tells me that the value is null.

Heh, 50 permutations won't make much of a difference ... unless they're
a version of the right approach. 😉 I can definitely empathize if you're
frustrated by now.

Are you testing your SWF inside your HTML page? If you're testing from
within Flash, then your external variable certainly isn't going to make it
into the SWF.

Here's a ZIP file that contains a working (extremely simple) example.
NOTE: This file is only going to be available for a week or so, as of this
date (July 10, 2008):

http://www.quip.net/kyle.zip

It contains an HTML page created by Dreamweaver. I used Dreamweaver to
embed kyle.swf and am feeding in the same parameter you're using
(instID=kyle). Dreamweaver creates AC_RunActiveContent.js, which is used to
embed the SWF, and puts that file into a subfolder named Scripts. Check out
the FLA and you'll see that it contains nothing more than a text field whose
instance name is instID_txt, and the single line of ActionScript:

instID_txt.text = root.loaderInfo.parameters.instID;


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2008 Jul 10, 2008
the code in your 07/10/2008 09:46:15 AM message works for me. though i'm not sure how using a static flashvars is going to help solve your problem.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2008 Jul 10, 2008
kglad,

> the code in your 07/10/2008 09:46:15 AM message works for
> me. though i'm not sure how using a static flashvars is going to
> help solve your problem.

Ah ... well, yes; that's true. I was under the impression 3cl3c71k0r
was working toward the goal in steps. First, get the static FlashVars to
work, as a proof of concept, then make the FlashVars dynamic.

I'm interested to see how 3cl3c71k0r comes along.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2008 Jul 10, 2008
maybe so. but i think it would be easier to access the location.href value using externalinterface.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2008 Jul 10, 2008
That's twice in one week, kglad! 😛 Some of us like to run around the
block to get to the neighbor's house! lol

dps


"kglad" <webforumsuser@macromedia.com> wrote in message
news:g56dcq$iou$1@forums.macromedia.com...
> maybe so. but i think it would be easier to access the location.href
> value using externalinterface.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 11, 2008 Jul 11, 2008
Thanks for your help, David. After testing your file, I discovered that the method worked on my local machine, my own personal hosting account, and NOT my business' hosting account. We're working right now to figure out why. I'm guessing it has something to do with our content management system. Kinda sucks to try fixing your alignment when one tire is flat.

Thanks again for your help!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 11, 2008 Jul 11, 2008
LATEST
eclectikor,

> Thanks for your help, David. After testing your file, I discovered
> that the method worked on my local machine, my own personal
> hosting account, and NOT my business' hosting account.

That sort of thing stinks. It's half the game, usually, just figuring
out why one seemingly irrelevant detail should matter. Good luck with that!

> I'm guessing it has something o do with our content management
> system. Kinda sucks to try fixing your alignment when one tire is
> flat.

That's not a bad thought. You might get something out of remote
debugging, which allows you to use the IDE's debugger workspace even when
you're testing from within a browser.

Check out Peter Elst's article:

http://www.adobe.com/devnet/flash/articles/as3_debugger.html


David Stiller
Contributor, How to Cheat in Flash CS3
http://tinyurl.com/2cp6na
"Luck is the residue of good design."


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2008 Jul 10, 2008
lol. that's a good one.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines