Skip to main content
wfzen
Inspiring
December 1, 2015
Answered

get values from Javascript

  • December 1, 2015
  • 1 reply
  • 988 views

I'm trying to pass an identification name or number from Javascript so I can use one SWF to pass data based on the page.

This works with ActionScript 2 but can't figure out why it does not with ActionScript 3:

<script type="text/javascript">

tPageID = 145;

function getPageID() {

     return tPageID;

}

</script>

Flash:

import flash.external.ExternalInterface;

var pageID = ExternalInterface.call("getPageID");

It seems it's always NULL with AS3.

Thanks for your help,

cpliu

This topic has been closed for replies.
Correct answer kglad

then your embedding html may be the problem.  change test2.swf to match your swf and fix the width/height values and try:

<!DOCTYPE html>

<html>

    <head>

        <meta charset="UTF-8">

        <title>test2</title>

        <style type="text/css" media="screen">

        html, body { height:100%; background-color: #ffffff;}

        body { margin:0; padding:0; overflow:hidden; }

        #flashContent { width:100%; height:100%; }

        </style>

       

        <script type="text/javascript">

tPageID = 145;

function getPageID() {

     return tPageID;

}

</script>

    </head>

    <body>

        <div id="flashContent">

            <object type="application/x-shockwave-flash" data="test2.swf" width="550" height="400" id="test2" style="float: none; vertical-align:middle">

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

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

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

                <param name="play" value="true" />

                <param name="loop" value="true" />

                <param name="wmode" value="window" />

                <param name="scale" value="showall" />

                <param name="menu" value="true" />

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

                <param name="salign" value="" />

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

                <a href="http://www.adobe.com/go/getflash">

                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />

                </a>

            </object>

        </div>

    </body>

</html>

1 reply

kglad
Community Expert
Community Expert
December 1, 2015

put the script tags in the head tags so that executes before your swf is embedded.

wfzen
wfzenAuthor
Inspiring
December 1, 2015

Yes, the Javascript was located before the code to load SWF. This is on SharePoint. I even move the Javascript to a different web part ahead of the script loading the SWF but it didn't make any difference.

If I try to pass the value to a text field, it always gets the following error; I assume this was caused by the null data:

TypeError: Error #2007: Parameter text must be non-null.

  at flash.text::TextField/set text()

  at AS_n_JS_AS3_fla::MainTimeline/frame1()

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
December 1, 2015

then your embedding html may be the problem.  change test2.swf to match your swf and fix the width/height values and try:

<!DOCTYPE html>

<html>

    <head>

        <meta charset="UTF-8">

        <title>test2</title>

        <style type="text/css" media="screen">

        html, body { height:100%; background-color: #ffffff;}

        body { margin:0; padding:0; overflow:hidden; }

        #flashContent { width:100%; height:100%; }

        </style>

       

        <script type="text/javascript">

tPageID = 145;

function getPageID() {

     return tPageID;

}

</script>

    </head>

    <body>

        <div id="flashContent">

            <object type="application/x-shockwave-flash" data="test2.swf" width="550" height="400" id="test2" style="float: none; vertical-align:middle">

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

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

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

                <param name="play" value="true" />

                <param name="loop" value="true" />

                <param name="wmode" value="window" />

                <param name="scale" value="showall" />

                <param name="menu" value="true" />

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

                <param name="salign" value="" />

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

                <a href="http://www.adobe.com/go/getflash">

                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />

                </a>

            </object>

        </div>

    </body>

</html>