SlideShare ist ein Scribd-Unternehmen logo
1 von 18
That’s a
                                            really small
                                            rhinoceros.




                                        +

Connecting Javascript and Flash
A Look into the ExternalInterface API
Our Cast of Characters

I’m so under-
dressed in that
   photo...




                  Javascript the Rhino   Flash the Snake
Pshaw.




Q: Why should we work together?
A: Because it lets you solve design problems
         that you couldn’t otherwise solve!

✤   “I want these embedded links in the           ✤   “I want to be able to select data from
    text I’m reading to take me to different          this Flex chart and then load an HTML
    chapters in this Flash movie.”                    data table onto the page for a deep dive
                                                      into the numbers.”
✤   “I want this text transcript to scroll
    while my Flash video is playing, and to       ✤   “I want to do usage reporting on user
    highlight the current line.”                      interactions with my .swf file. How can
                                                      I send these events to Google
✤   “I want to be able to filter this data table       Analytics?”
    using visual controls that aren’t part of
    standard HTML.”
Two Categories of Solutions
1. Outbound Control: Flash sends messages that affect other parts of
the page, outside of the swf




                                       Yeah, I’m
                                       the man!
                                       I mean snake.
Two Categories of Solutions
2. Inbound Control: Events that happen outside of the swf file control
what it displays
                                     Hey, don’t tread
                                         on me.


                            lol
Forget these jokers.
Let’s get into some code.
Two functions
     ActionScript:

     function showMessage(msg:String):void{
        msgHolder.text = msg;
     }




Javascript:
function makeAlert(msg){
   var label = document.getElementById('fromFlash');
   label.textContent = msg;
}
The steps

1. Make sure ExternalInterface is available

2. Set up your ActionScript callbacks

3. Have Flash call out to Javascript

4. Find your Flash object in the DOM

5a. Javascript calls ActionScript functions

5b. ActionScript calls Javascript functions
Step 1: Make sure it’s available

if (ExternalInterface.available)
{
    // do stuff
}
Step 2: Set up callbacks in ActionScript


ExternalInterface.addCallback("flashIsBetter", showMessage);



                     Name that will be used      Internal ActionScript
                     by Javascript to call the      function name.
                            function.




   (These two names can be the same or different.
   ExternalInterface will take care of mapping between the two.)
Step 3: Let Javascript know that you’re ready
You should always start by having the Flash file call out to the
Javascript. Otherwise, Javascript may try to call your ActionScript
functions before they are loaded and ready.

              ActionScript:
              ExternalInterface.call(“readyToGo”);


              Javascript:
              var flashReady = false;

              function readyToGo(){
                  alert('Flash is ready!');
                  flashReady = true;
              }
Step 4: Get your Flash object in Javascript
HTML:
<object id="demo"...>                  This is the Flash object on the page.
    ...                                Note that the id and name has been
    <embed name="demo".../>            set, so that you can get to the object
</object>                              easily with javascript.




Javascript:

function sendValueToFlash(){
   var flashObj;
   if (navigator.appName.indexOf("Microsoft") != -1) {
   
 flashObj = window["demo"];       The IE way.
   } else {
   
 flashObj = document["demo"];         The regular way.
   }
   ...
}
Step 5: Javascript calls ActionScript

Here we will use the callback that we set up in Step 2:
ActionScript:
ExternalInterface.addCallback("flashIsBetter", showMessage);




Javascript:
var text = document.getElementById('valueForFlash').value;
flashObj.flashIsBetter(text);


                We are using the external function name
                that was registered with addCallback.
Step 6: ActionScript calls Javascript
We’ve already seen this once, with our call to readyToGo.


ActionScript:

ExternalInterface.call(“makeAlert”, messageText.text);
Side-By-Side
Calling Javascript from ActionScript:
1. Create the Javascript function.

2. (No registration step required.)

3. ExternalInterface.call(“jsFunction”, ‘variable1’);




Calling ActionScript from Javascript:

1. Create the ActionScript function.

2. ExternalInterface.addCallback(“externalName”, “internalName”);

3. flashObject.externalName(‘variable1’, variable2);
A Few Gotchas
1. Flash objects in form tags break ExternalInterface in IE



2. Javascript operators in the name of the swf object break

ExternalInterface in IE



3. Ampersands get messed up when passed from Javascript

to ActionScript
Snake and Rhino celebrate their new-found friendship.


                              I guess
                        that wasn’t so bad.
                            High five!




                            .... I don’t
                           have arms.

Weitere ähnliche Inhalte

Was ist angesagt?

Maintainable JavaScript 2011
Maintainable JavaScript 2011Maintainable JavaScript 2011
Maintainable JavaScript 2011Nicholas Zakas
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesAbdul Rahman Sherzad
 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming languageMarco Cedaro
 
Redux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncRedux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncArtur Szott
 
Object Oriented Programming in Android Studio
Object Oriented Programming in Android StudioObject Oriented Programming in Android Studio
Object Oriented Programming in Android StudioMahmoodGhaemMaghami
 
The War is Over, and JavaScript has won: Living Under the JS Regime
The War is Over, and JavaScript has won: Living Under the JS RegimeThe War is Over, and JavaScript has won: Living Under the JS Regime
The War is Over, and JavaScript has won: Living Under the JS Regimematthoneycutt
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
Java script basics
Java script basicsJava script basics
Java script basicsJohn Smith
 
Lessons Learned: Migrating Tests to Selenium v2
Lessons Learned: Migrating Tests to Selenium v2Lessons Learned: Migrating Tests to Selenium v2
Lessons Learned: Migrating Tests to Selenium v2rogerjhu1
 
Desarrollo para Android con Groovy
Desarrollo para Android con GroovyDesarrollo para Android con Groovy
Desarrollo para Android con GroovySoftware Guru
 
Ruby on Rails from the other side of the tracks
Ruby on Rails from the other side of the tracksRuby on Rails from the other side of the tracks
Ruby on Rails from the other side of the tracksinfovore
 
REACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptREACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptDeepu S Nath
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalMax Pronko
 

Was ist angesagt? (18)

Maintainable JavaScript 2011
Maintainable JavaScript 2011Maintainable JavaScript 2011
Maintainable JavaScript 2011
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming language
 
Java scripts
Java scriptsJava scripts
Java scripts
 
Redux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncRedux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with Async
 
ReactJS
ReactJSReactJS
ReactJS
 
Object Oriented Programming in Android Studio
Object Oriented Programming in Android StudioObject Oriented Programming in Android Studio
Object Oriented Programming in Android Studio
 
The War is Over, and JavaScript has won: Living Under the JS Regime
The War is Over, and JavaScript has won: Living Under the JS RegimeThe War is Over, and JavaScript has won: Living Under the JS Regime
The War is Over, and JavaScript has won: Living Under the JS Regime
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
The evolution of asynchronous javascript
The evolution of asynchronous javascriptThe evolution of asynchronous javascript
The evolution of asynchronous javascript
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Lessons Learned: Migrating Tests to Selenium v2
Lessons Learned: Migrating Tests to Selenium v2Lessons Learned: Migrating Tests to Selenium v2
Lessons Learned: Migrating Tests to Selenium v2
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Desarrollo para Android con Groovy
Desarrollo para Android con GroovyDesarrollo para Android con Groovy
Desarrollo para Android con Groovy
 
Ruby on Rails from the other side of the tracks
Ruby on Rails from the other side of the tracksRuby on Rails from the other side of the tracks
Ruby on Rails from the other side of the tracks
 
Dojo1.0_Tutorials
Dojo1.0_TutorialsDojo1.0_Tutorials
Dojo1.0_Tutorials
 
REACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptREACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScript
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_Final
 

Ähnlich wie Connecting Flash and Javascript using ExternalInterface

JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4alexsaves
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of JavascriptTarek Yehia
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsMike Wilcox
 
Beyond the Basics, Debugging with Firebug and Web Inspector
Beyond the Basics, Debugging with Firebug and Web InspectorBeyond the Basics, Debugging with Firebug and Web Inspector
Beyond the Basics, Debugging with Firebug and Web InspectorSteven Roussey
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery維佋 唐
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Controlbhochhi
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipseanshunjain
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webpjcozzi
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfStephieJohn
 
JQUERY TUTORIALS
JQUERY TUTORIALSJQUERY TUTORIALS
JQUERY TUTORIALSMoize Roxas
 
Zyncro zyncro apps & ui customization feb 2013
Zyncro zyncro apps & ui customization feb 2013Zyncro zyncro apps & ui customization feb 2013
Zyncro zyncro apps & ui customization feb 2013Zyncro
 

Ähnlich wie Connecting Flash and Javascript using ExternalInterface (20)

All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
All of javascript
All of javascriptAll of javascript
All of javascript
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
Beyond the Basics, Debugging with Firebug and Web Inspector
Beyond the Basics, Debugging with Firebug and Web InspectorBeyond the Basics, Debugging with Firebug and Web Inspector
Beyond the Basics, Debugging with Firebug and Web Inspector
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipse
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
 
Javascript Workshop
Javascript WorkshopJavascript Workshop
Javascript Workshop
 
Flash Testing with Selenium RC
Flash Testing with Selenium RCFlash Testing with Selenium RC
Flash Testing with Selenium RC
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
 
JQUERY TUTORIALS
JQUERY TUTORIALSJQUERY TUTORIALS
JQUERY TUTORIALS
 
Zyncro zyncro apps & ui customization feb 2013
Zyncro zyncro apps & ui customization feb 2013Zyncro zyncro apps & ui customization feb 2013
Zyncro zyncro apps & ui customization feb 2013
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Jquery
JqueryJquery
Jquery
 

Kürzlich hochgeladen

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 

Kürzlich hochgeladen (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 

Connecting Flash and Javascript using ExternalInterface

  • 1. That’s a really small rhinoceros. + Connecting Javascript and Flash A Look into the ExternalInterface API
  • 2. Our Cast of Characters I’m so under- dressed in that photo... Javascript the Rhino Flash the Snake
  • 3. Pshaw. Q: Why should we work together?
  • 4. A: Because it lets you solve design problems that you couldn’t otherwise solve! ✤ “I want these embedded links in the ✤ “I want to be able to select data from text I’m reading to take me to different this Flex chart and then load an HTML chapters in this Flash movie.” data table onto the page for a deep dive into the numbers.” ✤ “I want this text transcript to scroll while my Flash video is playing, and to ✤ “I want to do usage reporting on user highlight the current line.” interactions with my .swf file. How can I send these events to Google ✤ “I want to be able to filter this data table Analytics?” using visual controls that aren’t part of standard HTML.”
  • 5. Two Categories of Solutions 1. Outbound Control: Flash sends messages that affect other parts of the page, outside of the swf Yeah, I’m the man! I mean snake.
  • 6. Two Categories of Solutions 2. Inbound Control: Events that happen outside of the swf file control what it displays Hey, don’t tread on me. lol
  • 7. Forget these jokers. Let’s get into some code.
  • 8. Two functions ActionScript: function showMessage(msg:String):void{ msgHolder.text = msg; } Javascript: function makeAlert(msg){ var label = document.getElementById('fromFlash'); label.textContent = msg; }
  • 9. The steps 1. Make sure ExternalInterface is available 2. Set up your ActionScript callbacks 3. Have Flash call out to Javascript 4. Find your Flash object in the DOM 5a. Javascript calls ActionScript functions 5b. ActionScript calls Javascript functions
  • 10. Step 1: Make sure it’s available if (ExternalInterface.available) { // do stuff }
  • 11. Step 2: Set up callbacks in ActionScript ExternalInterface.addCallback("flashIsBetter", showMessage); Name that will be used Internal ActionScript by Javascript to call the function name. function. (These two names can be the same or different. ExternalInterface will take care of mapping between the two.)
  • 12. Step 3: Let Javascript know that you’re ready You should always start by having the Flash file call out to the Javascript. Otherwise, Javascript may try to call your ActionScript functions before they are loaded and ready. ActionScript: ExternalInterface.call(“readyToGo”); Javascript: var flashReady = false; function readyToGo(){ alert('Flash is ready!'); flashReady = true; }
  • 13. Step 4: Get your Flash object in Javascript HTML: <object id="demo"...> This is the Flash object on the page. ... Note that the id and name has been <embed name="demo".../> set, so that you can get to the object </object> easily with javascript. Javascript: function sendValueToFlash(){ var flashObj; if (navigator.appName.indexOf("Microsoft") != -1) { flashObj = window["demo"]; The IE way. } else { flashObj = document["demo"]; The regular way. } ... }
  • 14. Step 5: Javascript calls ActionScript Here we will use the callback that we set up in Step 2: ActionScript: ExternalInterface.addCallback("flashIsBetter", showMessage); Javascript: var text = document.getElementById('valueForFlash').value; flashObj.flashIsBetter(text); We are using the external function name that was registered with addCallback.
  • 15. Step 6: ActionScript calls Javascript We’ve already seen this once, with our call to readyToGo. ActionScript: ExternalInterface.call(“makeAlert”, messageText.text);
  • 16. Side-By-Side Calling Javascript from ActionScript: 1. Create the Javascript function. 2. (No registration step required.) 3. ExternalInterface.call(“jsFunction”, ‘variable1’); Calling ActionScript from Javascript: 1. Create the ActionScript function. 2. ExternalInterface.addCallback(“externalName”, “internalName”); 3. flashObject.externalName(‘variable1’, variable2);
  • 17. A Few Gotchas 1. Flash objects in form tags break ExternalInterface in IE 2. Javascript operators in the name of the swf object break ExternalInterface in IE 3. Ampersands get messed up when passed from Javascript to ActionScript
  • 18. Snake and Rhino celebrate their new-found friendship. I guess that wasn’t so bad. High five! .... I don’t have arms.