HOw to write Actionscript to write Javascript

  • larnarnice
  • Born
  • Born
  • larnarnice
  • Posts: 3

Post 3+ Months Ago

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
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6254
  • Loc: Seattle, WA

Post 3+ Months Ago

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");
  • larnarnice
  • Born
  • Born
  • larnarnice
  • Posts: 3

Post 3+ Months Ago

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
  • Posts: 1827
  • Loc: In the Great White North

Post 3+ Months Ago

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

should work as well.
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6254
  • Loc: Seattle, WA

Post 3+ Months Ago

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
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1827
  • Loc: In the Great White North

Post 3+ Months Ago

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
  • larnarnice
  • Posts: 3

Post 3+ Months Ago

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