Need Help w/ ExternalInterface, SWFObject, LoadVars

  • DartHead
  • Beginner
  • Beginner
  • User avatar
  • Posts: 56
  • Loc: NYC

Post 3+ Months Ago

I'm using sendAndLoad to load an external HTML file into a text field within my SWF. I need to use a link in this text file to call a function in this same SWF (in order to change the page).

My SWF is structured so that the main body of AS is located in a movieclip in the second scene.

Is there anything special I have to do to use ExternalInterface with SWFObject to call a function in this location? The addCallback method is returning 'true' but the JS console tells me "Error: flashMovie.loadPage is not a function".

The SWFObject is set to allow script access.

Here's the JS:

Code: [ Select ]
var flashMovie;
function init() {
    if (document.getElementById) {
                flashMovie = document.getElementById("myMovie");
    }
}
// wait for the page to fully load before initializing
window.onload = init;

function openPage(){
    if(flashMovie){
        flashMovie.loadPage("MyPage");
    }
}
  1. var flashMovie;
  2. function init() {
  3.     if (document.getElementById) {
  4.                 flashMovie = document.getElementById("myMovie");
  5.     }
  6. }
  7. // wait for the page to fully load before initializing
  8. window.onload = init;
  9. function openPage(){
  10.     if(flashMovie){
  11.         flashMovie.loadPage("MyPage");
  12.     }
  13. }


Here's the AS:

Code: [ Select ]
import flash.external.*;
var connection = ExternalInterface.addCallback("openPage", null, loadPage);
  1. import flash.external.*;
  2. var connection = ExternalInterface.addCallback("openPage", null, loadPage);


And then, of course, there's the loadPage function itself, which does exist.

Thanks for your help!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • arakno
  • Beginner
  • Beginner
  • User avatar
  • Posts: 35
  • Loc: Lisboa

Post 3+ Months Ago

Hi, not sure if I understood correctly, anyway this is what i did to get x and y mouse position from a javascript function (getMousPos) into flash:

Code: [ Select ]
import flash.external.ExternalInterface;

function showMousPos():Void {
 mous = ExternalInterface.call("getMousPos");

}
  1. import flash.external.ExternalInterface;
  2. function showMousPos():Void {
  3.  mous = ExternalInterface.call("getMousPos");
  4. }


hope that helps...
  • DartHead
  • Beginner
  • Beginner
  • User avatar
  • Posts: 56
  • Loc: NYC

Post 3+ Months Ago

Hey arakno,

Thanks for your reply. The call() method is to get data from the container. I needed two-way communication. And, actually I figured it out.

Here was my actionscript:
Code: [ Select ]
import flash.external.*;
var connection = ExternalInterface.addCallback("openPage", null, loadPage);
  1. import flash.external.*;
  2. var connection = ExternalInterface.addCallback("openPage", null, loadPage);


And my javascript:
Code: [ Select ]
var flashMovie;
function init() {
  if (document.getElementById) {
      flashMovie = document.getElementById("myMovie");
  }
}
// wait for the page to fully load before initializing
window.onload = init;

function openPage(){
  if(flashMovie){
   flashMovie.loadPage("MyPage");
  }
}
  1. var flashMovie;
  2. function init() {
  3.   if (document.getElementById) {
  4.       flashMovie = document.getElementById("myMovie");
  5.   }
  6. }
  7. // wait for the page to fully load before initializing
  8. window.onload = init;
  9. function openPage(){
  10.   if(flashMovie){
  11.    flashMovie.loadPage("MyPage");
  12.   }
  13. }


My mistake was here:
Code: [ Select ]
flashMovie.loadPage("MyPage");


It should have been
Code: [ Select ]
flashMovie.openPage("MyPage");


because the first parameter of the addCallback() method is to identify a friendly name for the third parameter, which is the AS function you wish to call from JS.

Code: [ Select ]
addCallback("openPage", null, loadPage);


So "openPage" is what I call from JS and it refers to the loadPage function I defined in AS. The problem had nothing to do with loadVars or links in external textfiles.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.