Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a jQuery function using AS3

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

like image 355
Tisch Avatar asked Apr 10 '09 21:04

Tisch


People also ask

What does $( function ()) short hand do in jQuery?

Run Jquery function on page load once.

Where do I write function in jQuery?

Answer: Use the syntax $. fn. myFunction=function(){} The syntax for defining a function in jQuery is little bit different from the JavaScript.

Can I use instead of jQuery?

Nevertheless, Native javascript is one of the best jQuery alternatives, in fact, It is the framework of JS. Javascript is the best because any browsers ships with javascript and you do not need to install jQuery in your application.


2 Answers

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

like image 51
Ron DeVera Avatar answered Sep 19 '22 23:09

Ron DeVera


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...

like image 30
Tisch Avatar answered Sep 20 '22 23:09

Tisch