A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: passing vars to a swf in a popup window

  1. #1

    passing vars to a swf in a popup window

    I am having a devil of a time with this...


    I want to have my swf pop-up a javascript window with a swf in it and pass variables to it.

    this is the code to launch the popup:

    Code:
    on (release) { getURL("javascript:window.open(popup.html?desc=test','School','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no, width=280, height=260')", "GET");
    }
    I then have this line in my popup.html swf:

    Code:
    desctext.text = _root.desc+" HEY!";
    the dynamic text box (desctext) shows" undefined HEY!". AARRGH!!

    any ideas??

    thanks

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    This only works if you call the swf, not if its embedded in html .

    In your case you need a embed code like...

    ///URL TRANSFER OF VARIABLES

    PHP Code:
    <script language="JavaScript">
    document.write ('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
    +'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" '
    +'WIDTH=750 HEIGHT=500> <PARAM NAME=movie VALUE="knock.swf'+document.location.search+'">'
    +'<PARAM NAME=quality VALUE=high>'
    +'<EMBED src="knock.swf' +document.location.search+'" ' 
    +'quality=high  WIDTH=750 HEIGHT=500 '
    +'TYPE="application/x-shockwave-flash"></EMBED></OBJECT>')
    </
    script
    ...that would make your swf file get the variable as soon as its loaded.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    DANG THAT WAS FAST!

    nkay, well that is good to know but I am still a little confused about how this works.

    I have a list of about 340 items in the parent window that are going to popup a javascript window whenever they are selected. That window will load the same swf everytime but the dynamic text fields in the swf will be filled by the variables passed from the parent swf.

    that said. I don't understand the document.location.search part if the PARAM VALUE. Is that a variable passed from the parent? what does the button code look like?

    thank you very much

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    The button code is the one you use in your first post. Just add the variables to the url string.

    The javascript enhanced embed code just makes it possible for the swf to recieve those variables. So you can call the same html and swf on all buttons.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  5. #5
    thanks pellepiano but I couldn't get the doc.write to work correctly so I took another route.

    on my main swf I have a button that has this:
    Code:
    on (release) {
    	ayp_desc = "this is the variable that should go here";
    	getURL("javascript:NewWindow=window.open('test_popup.swf?ayp_descvar="+ayp_desc+"','newWin','width=280,height=260,left=0,top=0, toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');  NewWindow.focus(); void(0);");
    }
    this is now pointing at a swf instead of html. It pops up the same type of window and I don't have to work the swf to html to swf alchemy that I did before. In the test_popup.swf I have:
    a dynamic text box named ayp_desct and the following actionscript.


    Code:
    ayp_desct.text = ayp_descvar;
    This seems to be working just grand!


    Hopefully this will save someone elses hair.

    FLAV

  6. #6
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Its not doc.write but document.location.search and the embed code I wrote is for the recieving swf.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  7. #7
    BUGGERS!!

    sorry pellepiano I was refering to the javascript document.write.

    My solution has a couple of problems.

    1. pops up a blank window in firefox
    2. wont work in i.e. because my url is passing 34 different variables and the string makes the url too long.

    Pellepiano, just to be sure I understand:
    The document.location.search code goes in the popup window html?

    Can you think of another way to pass such a long string of variables? I'm guessing I'm going to run into the same i.e. problem even if I can use your code.

    Thank you

  8. #8
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    there seems to be a limit for url's at around 500 bytes (at least with the microsoft browser)

    You could possible make multiple calls to transfer a piece of text every time. I am not sure, however, whether there is a limit on the flashvars part as well.

    Would an approach retrieving the data from a server be possible?

    Musicman

  9. #9
    probably but I don't have to much experience wit that.

    Here is the situation:

    In an xml file I have a list of schools statewide (Minnesota, USA) broken down by school districts (340) within those districts are 1190 places of education (schools, universities, elementaries, etc.).

    I have divided the list of districts into 5 so that the xml file can be split five ways in order to keep them small.

    The project allows users to select any school from a list of school districts and compare its educational testing results with other schools.

    when the file first loads I already have the xml parsed so that all of the individual school results can be sent to the popup window.

    You can check it out at

    http://www.startribune.com/style/new...ft_behind.html

    WARNING: I haven't prettied it up yet :>

    Thanks for any suggestions.

  10. #10
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Another solution may be Local Connection, which allow communication between two swf files. The you can retrieve the variables when the pop up swf has loaded ( i believe ).

    http://actionscript.org/tutorials/in...ns/index.shtml

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  11. #11
    beautiful. Thanks pellepiano!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center