Skip to main content
July 18, 2008
Question

Targeting iframe with AS3

  • July 18, 2008
  • 8 replies
  • 3595 views
How do I do this so that it works properly?

I want to use navigation (buttons) built in flash to target the iframe that will be on the same page as the flash swf.
the user clicks the button ie. photos and the iframe is loaded with the html page that has been called. Then the next button is clicked and that iframe is loaded with different html content again or a movie or what ever.

There is a lot of junk code out there in web land. What is the correct way to do this without browser issues? ( yes I mean Internet Explorer) Do I need Java too?
This topic has been closed for replies.

8 replies

kglad
Community Expert
Community Expert
August 11, 2008
you're welcome.
kglad
Community Expert
Community Expert
August 9, 2008
use the frame name ("myIframe") instead of "_blank","_self" etc
Participant
August 11, 2008
Hey guys;
I did it another way and it works...

function gotoURL(url:String):void
{
var rURL:URLRequest = new URLRequest("contato.html");
navigateToURL(rURL,'recip');
}

There is no difference between this and the code you have posted, but it works without any problem only when I´ve changed the way to compose it .
Thanks for all assistance!!!

See you later..
Flavio
kglad
Community Expert
Community Expert
August 9, 2008
(i'm not sure you'll want to change your approach at this point, but just so you know the navigateToURL() function can directly target an iframe.)
Inspiring
August 9, 2008
kglad, great idea! Did not think about it...
Participant
August 8, 2008
HELLO Andrei!
Im from Brazil, so my english is not so good.

Im trying to use your script to load a html into a iframe with AS3. It´s working on Firefox but is not working in IE7.

Actually I don´t need to reload this iframe like VonPeters did. All I need is when I "click" in a button on swf, the html load in the named iframe. Can be on the Script? Could you please help me?

thanks a lot!
Inspiring
August 9, 2008
Hi,

IE may be catching the page. I suggest you append a random url variable to the href of frame every time you send request. As a matter of fact I find it to be a good practice to add a random url variable value every time request is sent (this includes requests from flash). For instance (JS): &rand=Math.floor(Math.random()*10000000) - you can use the current time too: &rand=new Date()).getTime()

Also, try document.frames['myIframe'].location.href = src; instead of window.frames['myIframe'].location.href = src;

I found a cool way to do that to accomodate all the browsers:

(document.frames || window.frames)['myIframe'].location.href = src;

Another approach could be to call the ir=frame by its ID:

var ifr = document.getElementById("frameID");
ifr.location.href = src;

Let me know if you solved this.
Participant
August 9, 2008
Thanks Andrei. Im trying to use your script suggestion, but its kind of complicate to me because I don´t know about JS, just start learning. But I´ll try and let you know...

tks!
July 31, 2008
My apologies

I had a capital letter in "homePage" and didn't change it to a lower case letter like in the page name "homepage".


Thanks so much for all your help!!!!!!!

working perfectly now!
Inspiring
August 1, 2008
I am glad things worked out.
July 31, 2008
Hey Andrei1

I just got back from a short Vacation and finally got time to test the script changes you were helping me with.

Thanks so much for your help!

I have another question regarding the last script. It appears that the frame
reloads properly. However the page is not being displayed properly.
and I get this message in its place each time I go to the "home page".

Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.8g DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at www.lazarowich.com Port 80

do you know how to get around this so the page loads properly?
July 19, 2008
Thanks a Million Andrei1

That works fantastically!!!



What do I have to adjust or add to the code: So that the next time the user goes to that site the home page is the first thing they see.

Currently the last page viewed is what stays loaded in the iframe the next time the site is visited.


Inspiring
July 20, 2008
Sorry, I don't quite understand what you are trying to accomplish. What home page? Do you mean there is a default iframe content that user has to see when he first land to the page?

If you mean that the last frame that was displayed is cached by browser - you perhaps need to add a function that will load the default html into iframe when your page loads.

If I understood it correct :

say your default page href is "homePage.html"

your script will look like this:
July 20, 2008
Yes that's exactly it - there is default iframe content that user has to see when he first sees the page.

That solution looks like exactly what is needed. Thanks so much for helping me out.

I will try it first thing Monday morning when I get to the studio!
Inspiring
July 18, 2008
You need to create a JavaScript functionality on the page and call these functions utilizing flash's ExternalInterface class.
July 19, 2008
ok cool.

and I place this in the head section of the html files i want to load?

what code do I put in? I don't know java (yet)

Inspiring
July 19, 2008
Say, your iframe is:

<iframe src="initialHTMLPage.html" name="myIframe"></iframe>