Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Run a function in flash when click a button on HTML page

Participant ,
Oct 16, 2012 Oct 16, 2012

dear friends,

i have loaded my swf in an html/ aspx page. when i click a button in html page, i want to pause my swf movie. Actually swf has another movie clip i want to stop that. any option pls help me. possible send me some sample coadings.. i tried with externalInterface but no result..

or if i click a button in html page, i want to run a function existing in loaded swf....

thanks in advance...

Thanks and Regards,

Syed Abdul Rahim

TOPICS
ActionScript
4.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 16, 2012 Oct 16, 2012

Can you show what you tried using the ExternalInterface class.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 16, 2012 Oct 16, 2012

Dear Mr.Ned,

Greetings! Thks for your reply.

in flash i used the following code:

import flash.external.ExternalInterface;

ExternalInterface.addCallback("methodName", method );

function method() {

    mytxt.text = "call from java script";

    trace("called from javascript");

}

in html (published from flash) i used the following code:

</script>

<script language="javascript" type="text" >

function callAS() {

   swf.methodName();

}

in on load i used: <body bgcolor="#ffffff" onLoad="callAS()">

------------------------------------------

when i open my html file it shows the error like, "this file is trying to communicate with Internet"

please help me;

please clarify me whether i used correct javascipt in right place in html, becoz i dont know much in java... and html...

Thanks and Regards,

Syed Abdul Rahim

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 16, 2012 Oct 16, 2012

You should test live on a server to get around the security issues. 

Aside from what you show, which appears correct, did you assign the id "swf" to the Flash object code tags in the html file?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 17, 2012 Oct 17, 2012

Dear Mr.Ned MUrphy,

Greetings! thks for ur answer. s, i copied to internet server and i gave id also, still it is not working pls check and tell me i have modified my coding as below:

flash code:

import flash.external.ExternalInterface;

ExternalInterface.addCallback("methodName", method );

function method() {

    mytxt.text = "call from java script";

    trace("called from javascript");

}

--------------------------------------------------------------------------

HTML code...

  <script language="javascript" type="text" >

function methodName() {

   swf.method();

   alert("hi.. u clicked me?");

}

</script>

 

  <script language="javascript">

    if (AC_FL_RunContent == 0) {

        alert("This page requires AC_RunActiveContent.js.");

    } else {

        AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','550','...' ); //end AC code

    }

</script>

  <noscript>

    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="jscr_rd" align="middle">

      <param name="allowScriptAccess" value="sameDomain" />

      <param name="allowFullScreen" value="false" />

      <param name="movie" value="jscr_rd.swf" />

      <param name="quality" value="high" />

      <param name="bgcolor" value="#ffffff" />   

      <embed src="jscr_rd.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="jscr_rd" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />   

  </object>

  </noscript>

</p>

<form name="form1" method="post" action="">

  <label>Click me

  <input type="submit" name="but" id="but" value="Submit" onClick="methodName()">

  </label>

</form>

<p> </p>

</body>

</html>

Thanks and Regards,

Syed Abdul Rahim

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 17, 2012 Oct 17, 2012

for addCallback, either use swfobject to embed your swf or use the sample embedding code shown in the flash help files under the addCallback method.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 17, 2012 Oct 17, 2012

Your code from before was correct.  You seem to have changed it now where it will not be correct.  You need to use the "methodName()" in the javascript code like you did originally.

Also, If you notice in your javascript function you are targeting the swf using "swf"...

     swf.methodName();

But the id you assign to the swf in the html embedding code is "jscr_rd".  You need to use the id you assign to target the Flash file in the javascript code.

I would place the javascript function in the head section of the html file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 18, 2012 Oct 18, 2012

Dear Mr.ned,

Greetings! i tried to put the id also, still its not working.. any ideas? find below my codings:

flash code:

import flash.external.ExternalInterface;

ExternalInterface.addCallback("methodName", method );

function method() {

    mytxt.text = "call from java script";

    trace("called from javascript");

}

---------------------------------

HTML code:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>jscr_rd</title>

<script language="javascript">AC_FL_RunContent = 0;</script>

<script src="AC_RunActiveContent.js" language="javascript"></script>

</head>

<body bgcolor="#ffffff">

<p>

  <!--url's used in the movie-->

  <!--text used in the movie-->

  <!--

<p align="left"></p>

-->

  <!-- saved from url=(0013)about:internet -->

  </script>

 

  <script language="javascript" type="text" >

function methodName() {

   jscr_rd.method();

   window.alert("hi.. u clicked me?");

}

</script>

 

  <script language="javascript">

    if (AC_FL_RunContent == 0) {

        alert("This page requires AC_RunActiveContent.js.");

    } else {

        AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','550','...' ); //end AC code

    }

</script>

  <noscript>

    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="jscr_rd" align="middle">

      <param name="allowScriptAccess" value="sameDomain" />

      <param name="allowFullScreen" value="false" />

      <param name="movie" value="jscr_rd.swf" />

      <param name="quality" value="high" />

      <param name="bgcolor" value="#ffffff" />   

      <embed src="jscr_rd.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="jscr_rd" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />   

  </object>

  </noscript>

</p>

<form name="form1" method="post" action="">

<input name="but" type="button" value="click me" onClick="methodName()">

</form>

<p> </p>

</body>

</html>

---------------------------------

pls check advice me

Thanks and Regards,

Syed Abdul Rahim

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 19, 2012 Oct 19, 2012
LATEST

You are still using the Flash function name where you need to use the string reference to it: methodName

Here is a link to a working version of the code you used in your first posting.  If you right click the web page you should be able to click an option to view the source code for the page.

http://www.nedwebs.com/Flash/AS3_EI.html

In it you will see the various things I suggested you do.  The script is located in the head section of the html code.  That script uses the "swf" id to target the Flash swf file, and the html embedding code assigns "swf" as the id for the the Flash object.

It still uses the onLoad approach to get the function to execute, but that is something you should be able to implement a button for instead.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines