4

I have a project building an expandable web banner and I'm having trouble with using Flash's external interface call.

What I'm trying to do is initiate a jQuery function on my HTML page by clicking a button inside of my .swf banner.

The jQuery function simply expands a to reveal another .swf file.

---This is the jQuery code in the head of my HTML page---

<script type="text/javascript">

$(document).ready
(function()
    {
    $(".contentBox").hide();

        $(".bannerBox").click
        (function expand()
            {
            $(".contentBox").slideToggle();
            }
        );
    }
);

</script>

---This is my actionscript code---

clickMe.addEventListener(MouseEvent.CLICK,fnMouseOn);
function fnMouseOn(e:MouseEvent):void 
{
   ExternalInterface.call('expand()')
}

Sorry if this question has already been answered elsewhere and I haven't understood, I've been searching for a solution for a few hours now and I haven't been able to figure it out.

Any help appreciated :-)

  • 1
    I'm not a JS expert, but it kind of seems like your `expand()` function is defined inside of an anonymous function. And thus Actionscript may not have access to that function? Also (probably not an issue), you normally leave off the parentheses in the function name when using ExternalInterface: `ExternalInterface.call('expand')`. Finally, it might help if you describe what happens when the problem occurs. – Sunil D. Oct 18 '12 at 20:27

1 Answers1

2

Sunil D. Has it right. The expand function only exists within the context of the click assignment, and can't be called otherwise, but with a little refactor you should be good to go:

<script type="text/javascript">

$(document).ready
(function()
    {
    $(".contentBox").hide();

        $(".bannerBox").click
        (function(){expand();}
        );
    }
);

function expand(){
  $(".contentBox").slideToggle();
}
</script>
invertedSpear
  • 10,864
  • 5
  • 39
  • 77