HOw to write Actionscript to write Javascript

  • larnarnice
  • Born
  • Born
  • No Avatar
  • Joined: Sep 28, 2007
  • Posts: 3
  • Status: Offline

Post September 28th, 2007, 11:47 am

hello all! this is my first post and its driving me crazy:

I want to write an actionscrip getURL in my flash movie on a certain frame that
will call this specific javascript code:

<script language="JavaScript" type="text/javascript">
ord=Math.random()*10000000000000000;
document.write('<a href="http://www.blahblahblah.com " target="_blank">');
document.write('<img src="http://www.blahblahblah.com/image1.jpg " width="0" height="0" border="0" alt=""></a>');
</script>

what is the syntax to use and where do I put the JS code?

all help is appreciated, thanks !
:D
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 28th, 2007, 11:47 am

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6130
  • Loc: Seattle, WA
  • Status: Offline

Post September 28th, 2007, 12:52 pm

Place the Javascript code inside of a function, and then use the ExternalInterface class's call() method to call the Javascript function from within ActionScript.

In the HTML:
Code: [ Select ]
<script language="JavaScript" type="text/javascript">

function makeImageLink()
{
  ord=Math.random()*10000000000000000;

  document.write('<a href="http://www.blahblahblah.com " target="_blank">');

  document.write('<img src="http://www.blahblahblah.com/image1.jpg " width="0" height="0" border="0" alt=""></a>');
}

</script>
  1. <script language="JavaScript" type="text/javascript">
  2. function makeImageLink()
  3. {
  4.   ord=Math.random()*10000000000000000;
  5.   document.write('<a href="http://www.blahblahblah.com " target="_blank">');
  6.   document.write('<img src="http://www.blahblahblah.com/image1.jpg " width="0" height="0" border="0" alt=""></a>');
  7. }
  8. </script>


In the Flash:
Code: [ Select ]
ExternalInterface.call("makeImageLink");
The Beer Monocle. Classy.
  • larnarnice
  • Born
  • Born
  • No Avatar
  • Joined: Sep 28, 2007
  • Posts: 3
  • Status: Offline

Post September 28th, 2007, 1:07 pm

Thanks so much!
my JS sux so i had no idea i could just put everything into a function...hooray!
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Joined: Jul 11, 2005
  • Posts: 1828
  • Loc: In the Great White North
  • Status: Offline

Post September 28th, 2007, 7:10 pm

otherwise
Code: [ Select ]
getURL("javascript:javascriptfunctionName();");

should work as well.
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6130
  • Loc: Seattle, WA
  • Status: Offline

Post September 30th, 2007, 12:40 pm

getURL() doesn't give you as much control over the call. With ExternalInterface, you can more or less use the Javascript function as a remote procedure, complete with callbacks and all that other cool jazz.

Adobe wrote:
Use of ExternalInterface is recommended for all JavaScript-ActionScript communication.

http://livedocs.adobe.com/flex/201/lang ... rface.html
The Beer Monocle. Classy.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Joined: Jul 11, 2005
  • Posts: 1828
  • Loc: In the Great White North
  • Status: Offline

Post September 30th, 2007, 6:58 pm

very true. that is actually a much better solution.

unfortunately most people's flash/javascript interaction is something light weight like communicating with urchin or opening a window without a menu bar in which case I usually provide getURL() solution to make life easier.
  • larnarnice
  • Born
  • Born
  • No Avatar
  • Joined: Sep 28, 2007
  • Posts: 3
  • Status: Offline

Post October 1st, 2007, 7:15 am

thanks guys-
I am still having some bugs- I know its not a JS forum, but do you know if there is a problem if the function is not named from within the <head>tag? I have limited access to the html of the page i am embedding my content into so if there is a limitation on that I will try out the basic getURL method. ah well.

good stuff-
thanks

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 39 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
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.