7

I am trying to run a jQuery function on my HTML page from AS3.

This is my jQuery function:

function loadImage(imageNumber)
  {
    imageURL = '<img src="images/image' + imageNumber + '.jpg">';
    $("#imageBox").html(imageURL);
  }

Here are the settings of my flash file in the HTML page:

<param name="allowScriptAccess" value="always" />
<param name="bgcolor" value="#ffffff" />    
<embed src="links.swf" quality="high" bgcolor="#ffffff" width="320" height="242" name="links" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />

and finally... here is the AS3 script in my .swf file:

function gotoImage1(e:MouseEvent):void {
    var jscommand:String = "loadImage(1);"
    var link:URLRequest = new URLRequest("javascript:" + jscommand + "");
    navigateToURL(link, '_self');
}

Thankyou in advance for taking the time to look and any help is massively appreciated.

Kindest Regards.Tom

2 Answers 2

6

You can use ExternalInterface instead:

if (ExternalInterface.available) {
    ExternalInterface.call('function(){ alert("test"); }');
}

Documentation: http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html

Sign up to request clarification or add additional context in comments.

2 Comments

Thankyou for the fast response, although I got the alert("test") to show, I can not get my function to run. The function at the top of my HTML page is called "loadImage". I'm also passing a variable to this function. if(ExternalInterface.available){ ExternalInterface.call('loadImage(1);'); }
not to worry. ive got it working. Thankyou very much for the answer. Muchos appreciated :)
1

The final solution was:

function gotoImage2(e:MouseEvent):void 
{
    if(ExternalInterface.available)
    {
        ExternalInterface.call('function(){ loadImage(2); }');
    }
}

Just in case anyone wanted to see how it ended...

1 Comment

Why don't you call directly your javascript method instead of using an anonymous function? ExternalInterface.call('loadImage', 2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.