14 October 2007 ~ 39 Comments

Opening a ThickBox iframe from Flash

If you don’t know what is ThickBox, check it out here: http://jquery.com/demo/thickbox/

That’s some nice way to present content on your site right? Anyway, I’ve been playing around with ThickBox for quite some time now, and a recent project required me to call up a ThickBox iframe from within Flash itself.

As the documentation on the site only provided HTML help on how to implement ThickBox, I had to look for a way to do this myself. A search on Google yielded a few complicated ways to do this, which I did not think was effective since they involved writing of new Javascript functions. Then, I found this article which describes how to do almost exactly what I wanted – but, it requires a writing of a new function. And, it is opening an image, and not an iframe.

With what I learnt from the article, I went to take a look at ThickBox’s code. Thanks to their neat comments, I understood how the functions work after a few minutes, and I implemented what I learnt from the article (which is how to use ExternalInterface) to do exactly what I wanted.

The idea is to call the Javascript function that launches a iFrame ThickBox from thickbox.js. The function name is actually tb_show, with 3 parameters that you can pass in, namely, the caption, url and imageGroup. Obviously, what I need to pass in here is the URL.

Therefore, with the ExternalInterface, this is the code I need to put into Flash:

import flash.external.ExternalInterface;
Button.onRelease = function(){
ExternalInterface.call(“tb_show” , null ,”page.html?KeepThis=true&TB_iframe=true&height=150&width=150″ , false);
}

If that doesn’t make sense to you, you need to see how ThickBox is launched with HTML originally:

<a href="page.html?KeepThis=true&TB_iframe=true&height=150&width=150" class="thickbox"> Click Here </a>

You can see that it requires the a tag to have a “thickbox” class. Which is why you can’t just use a getURL in Flash.

I hope this helps people out there. =)

  • Share/Bookmark

Related posts:

  1. stop all sounds in Flash AS3 You can call it the global mute as well....
  2. Update your Flash CS4 If, for some reason, you’re still on Flash CS4...

Related posts brought to you by Yet Another Related Posts Plugin.

39 Responses to “Opening a ThickBox iframe from Flash”

  1. Hugo 16 October 2007 at 5:00 am Permalink

    Hi there, I tried to implement your code but got no success… nothing happens, is it complete?

  2. DarkSuiyoken 16 October 2007 at 11:36 am Permalink

    Hi,

    Yea, it is complete… Can you show me your page and your code?

  3. Hugo 16 October 2007 at 8:21 pm Permalink

    Ok, here is the actionscript (it’s a 1 frame movie, just for testing purposes), and the code is in timeline:

    import flash.external.ExternalInterface;
    Botao.onRelease = function() {
    ExternalInterface.call(“tb_show”, “teste”, “teste.html?KeepThis=true&TB_iframe=true&height=150&width=150″, false);
    };

    Now the html file:

    teste_thickbox

    `

    @import “Scripts/thickbox.css”;



    AC_FL_RunContent( ‘codebase’,'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0′,’width’,'400′,’height’,'400′,’id’,'teste_thickbox’,'align’,'middle’,’src’,'teste_thickbox’,'quality’,'high’,'bgcolor’,'#66ccff’,'name’,'teste_thickbox’,'allowscriptaccess’,’sameDomain’,'pluginspage’,'http://www.macromedia.com/go/getflashplayer’,'wmode’,'transparent’,'movie’,'teste_thickbox’ ); //end AC code

     
    Example 1

    Please notice that the html code (www.google… etc) does work!

    Nothing happens when I click the flash button =( Am I doing anything wrong? Thanks in advance!

  4. Hugo 16 October 2007 at 8:24 pm Permalink

    Hmmm… sorry, I think I’ve messed up your page width

  5. DarkSuiyoken 16 October 2007 at 8:28 pm Permalink

    It’s ok, lol.

    Try using swfObject to load in your swf.

    And for the ExternalInterface calling, try to replace your “teste” to null instead. I’m not exactly sure what that argument does, but I didnt need it.

    It’ll also help if you set up this on your server and link me to it, so I can take a look.

  6. Hugo 16 October 2007 at 8:44 pm Permalink

    Man… no success here =(

    I`ve uploaded it: http://www.dmndesign.com.br/cal/teste_thickbox.html

    Thanks in advance!

  7. DarkSuiyoken 16 October 2007 at 8:54 pm Permalink

    Hey,

    For me, the HTML link didn’t work too..

    I noticed that the JS files aren’t in the directory where you linked them to be. They should be in a folder called “Scripts” where your html page is.

  8. Hugo 16 October 2007 at 8:57 pm Permalink

    Oooops, dude, sorry, forgot to upload the .js files… it’s ok now, the html works but the flash does not… :(

  9. DarkSuiyoken 16 October 2007 at 9:02 pm Permalink

    Hey Hugo,

    It’s actually working for me, you do not have the teste.html file right? That’s why it’s showing a page not found error within the iframe. Try changing your code to the following to see if Google loads up fine instead. =]

    import flash.external.ExternalInterface;
    Botao.onRelease = function(){
    ExternalInterface.call(“tb_show” , null ,“http://www.google.com/?keepThis=true&TB_iframe=true&height=500&width=770? , false);
    }

  10. Hugo 16 October 2007 at 9:39 pm Permalink

    Dude, I’ve tested with urls, files, everything… It was not working, I really dunno why. Maybe a typo somewhere?

    Well, thank you very much, I feel bad about wasting your time, so thank you very much once again.

    PS: http://www.dmndesign.com.br/cal/ is the project I’m working on, just to let you know =) Thanks!

  11. DarkSuiyoken 16 October 2007 at 9:51 pm Permalink

    Pretty sleek work there.

    Don’t worry about me wasting my time. =] I’m not too sure if this method of mine works 100% for everyone too, so I wanna know what will make it not work, and what it needs to work.

    Have you tried to embed your flash with swfObject instead?

    http://blog.deconcept.com/swfobject/

  12. Hugo 18 October 2007 at 3:15 am Permalink

    Man, thank you very much once again. I’ve been working on that project, when it’s complete I’ll show ya ;) PS: email is gtalk too, in case you want it! Cya!

  13. DarkSuiyoken 18 October 2007 at 3:20 am Permalink

    Hey, cool. Did it work in the end? =]

  14. jason 21 October 2007 at 6:55 am Permalink

    Help! The html works but it wont work from flash

  15. jason 21 October 2007 at 7:00 am Permalink

    the button seems to be calling a function that triggers the error: “undefined”

  16. DarkSuiyoken 21 October 2007 at 11:00 am Permalink

    Hmm the undefined should be from another part of your script that used a trace command.

    Are you using Flash 8? Publishing with Flash 8?

  17. jason 21 October 2007 at 3:36 pm Permalink

    Can you please help me with the flash file. I have really need this project for Monday/

  18. DarkSuiyoken 21 October 2007 at 3:39 pm Permalink

    sure, email it to me at darksuiyoken[at]gmail[dot]com

  19. jason 21 October 2007 at 4:04 pm Permalink

    I emailed you the flash file. Thank You!

  20. jack 26 October 2007 at 4:36 pm Permalink

    Hello,

    My thickbox wont open.

    I have a i frame long movie and in one layer i have:

    import flash.external.ExternalInterface;
    but1.onRelease = function(){
    ExternalInterface.call(“tb_show” , null ,”next.html?KeepThis=true&TB_iframe=true&height=150&width=150″ , false);
    }

    in the other layer i have a button called but1.

    what did i do wrong? do u have a online example somewhere?

    thanks!

  21. DarkSuiyoken 7 November 2007 at 8:50 pm Permalink

    hi jack,

    you can get the source files from my this post:
    http://designfission.com/blog/2007/10/21/followup-opening-a-thickbox-iframe-in-flash/

  22. Qbic 23 November 2007 at 8:20 am Permalink

    great solution ;)

  23. Jeff Phillips 5 December 2007 at 8:29 am Permalink

    You’re awesome buddy! Thanks a million. Works like a charm. I would have worked on this forever maybe if you hadn’t taken the few minutes to blog your findings. I googled “call thickbox from flash” and you were #2, (just below the article you mention in your post =).

    I’ll pass on the good karma as best I can!

  24. jerang 3 February 2008 at 10:29 am Permalink

    Thanks for the great article. For those who have flash embeded in HTML and are having trouble with iframe interference, just add wmode=transparent as an attribute and paramater.

  25. Markc 27 February 2008 at 6:52 pm Permalink

    I’ve got this working in IE6, Firefox and Safari but can’t get it working in Opera – any ideas?

  26. DarkSuiyoken 8 March 2008 at 11:47 pm Permalink

    hi mark,

    I don’t really have the time to make it work for Opera right now. If you ever find a solution, do share it here! ;)

  27. Max 10 April 2008 at 9:58 pm Permalink

    Hey, you helped me a lot. Thanks!

  28. Brandon 13 June 2008 at 7:09 am Permalink

    Hi,

    I am actually trying to do the same thing with my website–call thickbox from a flash movie, but I am having no luck. The HTML thickbox links work great, but I cant get the links to work from the flash movies.

    Is there anyway you could personally help me (by phone or email), and I would be willing to pay you for your time. If so, please send me an email.

    Thanks,
    Brandon

  29. tristen 23 September 2008 at 1:04 am Permalink

    I know this is an older post but it would be nice if your example worked!

  30. DarkSuiyoken 23 September 2008 at 1:06 am Permalink

    Did you look at the newer post? :)

    http://designfission.com/blog/2007/10/21/followup-opening-a-thickbox-iframe-in-flash/

  31. Chris Homan 24 September 2008 at 2:00 pm Permalink

    Hey There,

    I came across this thread, and was hoping someone could help, im going crazy! I’ve been developing a site with jQuery tabs, innerfade, and swfObject, with much success. My plan was to integrate thickbox for the individual images, but for some reason, i can’t even get thickbox to kick in. The browser just goes right to the image in a new window. I know it’s something silly, could anyone help me out? I’ve worked with lightbox quite a bit, but even that wouldn’t work when i tried integrating it onto the page. Right now i’m just testing on one page, the first thumbnail (phoenix adult), that should definitely be doing some thickbox magic…have a look at the code…

    http://dev.creativehinge.com/portfolio_temp.php

  32. DarkSuiyoken 24 September 2008 at 7:38 pm Permalink

    Hi Chris,

    My post is about opening a thickbox frame from flash, but your site is actually purely Thickbox with HTML/CSS. Perhaps you should look on the ThickBox community for help for this.

  33. George 2 October 2008 at 11:44 pm Permalink

    Simply Excellent Post

  34. kppmbbwpuj 21 January 2009 at 1:37 am Permalink

    lGVBav afjsokjjewil, [url=http://mzmgjmeuiwoy.com/]mzmgjmeuiwoy[/url], [link=http://wzanriwvqccc.com/]wzanriwvqccc[/link], http://lgrgfszslhhf.com/

  35. ricmetal 4 April 2009 at 6:13 am Permalink

    thanks for that

  36. Chris 6 April 2009 at 7:15 pm Permalink

    Thanks alot for this!

    worked just fine, the .fla file was real handy!
    keep it up!

  37. Paul 24 June 2009 at 12:40 am Permalink

    This worked perfectly! Thank you very much.

  38. Nando 29 September 2009 at 4:19 am Permalink

    Any chance I can still get some help with this issue?
    I have it working on Safari and Firefox but will not work on IE.
    Here is what I have from Flash:

    ExternalInterface.call(“tb_show”,”Sample Game”,link+”?&keepThis=true&TB_iframe=true&height=550&width=375″,false);

    Where “link” is a variable that holds the link value pulled from an XML document. I also omitted the “null” parameter because when I added it just won’t work on ANY of the browsers..go figure.

    Again, this works on FF and Safari but IE gives me a- ‘null’ is null or not an object – error.

    Any help would be greatly appreciated.

  39. Nando 29 September 2009 at 4:20 am Permalink

    Sorry, forgot to post a link to my site:

    http://www.internationalgamecard.com/sample.php

    Test on all browsers and notice the difference

    Thanks


Leave a Reply

UA-2806383-1