Actionscript-Javascript Interaction
From Wikicliki
I needed to make a html file with embedded flash that had the javascript on the html page triggering events in the flash and vice versa. This is the final solution which was used.
HTML
<a id="BM" href="bermuda.html" onMouseover="asMouseOver(this.id)" onMouseout="asMouseOut(this.id)">Bermuda</A>
Actionscript
- COLOURWANG = using prototype to define the clearRGB function for the mouseOut
- FUNCTIONWANG = defines the mouseovers and mouseouts colour changes
- COUNTRYFUNCTIONWANG = defines the rollovrs and rollouts for the mouseovers and mouseouts hover captions functions (for each specific movieclip)
- WORDWANG = defines the hover caption function
- EXTERNALINTERFACEWANG = externalinterface callback that allows Actionscript to access the Javascript functions (by declaring them in advance)
import flash.external.ExternalInterface; // COLOURWANG! Color.prototype.clearRGB = function(){ this.setTransform({ra:100, rb:0,ga:100,gb:0,ba:100,bb:0,aa:100,ab:0}); } // FUNCTIONWANG! function countryOver(id) { var newColor = new Color(eval(id)); newColor.setRGB(0x2A87AC); } function countryOut(id) { var newColor = new Color(eval(id)); newColor.clearRGB(); } function countryOverHTML(id){ ExternalInterface.call("countryMouseOver",id); } function countryOutHTML(id){ ExternalInterface.call("countryMouseOut",id); } // COUNTRYFUNCTIONWANG! BM.onRollOver = function() { countryName(true, "Bermuda", this); countryOver("BM"); countryOverHTML("BM"); this.onRollOut = function() { countryName(false); countryOut("BM") countryOutHTML("BM"); }; }; // WORDWANG! countryName = function (showCaption, captionText, bName) { if (showCaption) { _root.createEmptyMovieClip("hoverCaption", this.getNextHighestDepth()); cap.desc.text = captionText; cap._width = 8*cap.desc.text.length; cap._alpha = 75; hoverCaption.onEnterFrame = function() { cap._x = _root._xmouse; if ((cap._x-(cap._width/2))<0) { cap._x = cap._width/2; }else if((cap._x + (cap._width/2))>330){ cap._x = 330 - (cap._width/2); }else{ } cap._y = _root._ymouse-15; cap._visible = true; }; } else { delete hoverCaption.onEnterFrame; cap._visible = false; } }; // EXTERNALINTERFACEWANG! var method1:Function = countryOver; var method2:Function = countryOut; var instance:Object = null; ExternalInterface.addCallback("textMouseOver", instance, method1); ExternalInterface.addCallback("textMouseOut", instance, method2);