IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Int�raction Javascript - Flash


Sujet :

JavaScript

  1. #1
    Membre confirm�
    Avatar de jak0
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    272
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 272
    Par d�faut Int�raction Javascript - Flash
    Bonjour � tous,

    Ne connaissant absolument rien en Flash, je me permets de faire appel � vos connaissances...

    J'aimerai savoir si, depuis javascript, il est possible d'appeler des fonctions d'un �l�ment flash. En fait, controller le comportement d'un �l�ment flash en appelant des fonctions de cet �l�ment depuis javascript.

    J'ai entendu parler de fscommand, mais �a reste plutot vague.

    Merci de votre aide ++

  2. #2
    Membre confirm� Avatar de Iori Yagami
    �tudiant
    Inscrit en
    Mai 2007
    Messages
    107
    D�tails du profil
    Informations personnelles :
    �ge : 39

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 107
    Par d�faut
    Salut
    Oui c'est possible grace a fscommands(), mais en flash 8, c'est plus pratique en utilisant la commande : ExternalTools.CallBack();
    voici un exemple, qui peut te servir :
    <code>
    /**
    * Box2.as: ActionScript code to demonstrate JavaScript <-> Flash communication
    * using the ExternalInterface class of Flash 8.
    *
    * Compile this code using mtasc with a command like this:
    *
    * mtasc -version 8 -header 300:300:1 -main -swf Box2.swf Box2.as
    *
    * If you use the Flash IDE instead, insert a call to Box.main( ) in the
    * first frame of your movie.
    */
    import flash.external.ExternalInterface;

    class Box {
    static function main( ) {
    // Use the new External Interface to export our ActionScript function.
    // This makes it very easy to invoke the function from JavaScript,
    // but it is only supported by Flash 8 and later.
    // The first argument of addCallback is the name by which the function
    // will be known in JavaScript. The second argument is the
    // ActionScript object on which the function will be invoked. It
    // will be the value of the 'this' keyword. And the third argument
    // is the function that will be called.
    ExternalInterface.addCallback("drawBox", null, function(x,y,w,h) {
    _root.beginFill(0xaaaaaa, 100);
    _root.lineStyle(5, 0x000000, 100);
    _root.moveTo(x,y);
    _root.lineTo(x+w, y);
    _root.lineTo(x+w, y+h);
    _root.lineTo(x, y+h);
    _root.lineTo(x,y);
    _root.endFill( );
    return w*h;
    });

    // This is an ActionScript event handler.
    // Tell JavaScript about mouse clicks using ExternalInterface.call( ).
    _root.onMouseDown = function( ) {
    ExternalInterface.call("reportMouseClick",
    _root._xmouse, _root._ymouse);
    }

    // Tell JavaScript that we're fully loaded and ready to be scripted.
    ExternalInterface.call("flashReady");
    }
    }

    </code>

    et en javascript :

    <code>
    // When an ActionScript function is exported with ExternalInterface.addCallback,
    // we can just call it as a method of the Flash object.
    function draw( ) {
    var flash = window.movie || document.movie; // Get Flash object
    return flash.drawBox(100, 100, 100, 50); // Just invoke a function on it
    }

    // These are functions Flash will call with ExternalInterface.call( ).
    function flashReady( ) { document.f.button.disabled = false; }
    function reportMouseClick(x, y) { alert("click: " + x + ", " + y); }
    </code>

    extrait de JavaScript reference guide de O'Reilly
    Le probl�me est que �a n'a pas encore march� avec moi

  3. #3
    Membre exp�riment�
    Profil pro
    Inscrit en
    F�vrier 2007
    Messages
    265
    D�tails du profil
    Informations personnelles :
    �ge : 42
    Localisation : France

    Informations forums :
    Inscription : F�vrier 2007
    Messages : 265
    Par d�faut
    Salut,

    je n'ai jamais essay� ce que tu dis mais j'ai trouv� un lien qui a l'air pas mal :

    http://www.communitymx.com/content/a...491&print=true

    A toi de voir s'il te sert vraiment maintenant !

Discussions similaires

  1. Communication Javascript/Flash et IE
    Par Fredovsky dans le forum G�n�ral JavaScript
    R�ponses: 0
    Dernier message: 11/06/2008, 16h34
  2. [javascript] Flash clickable
    Par lthomas dans le forum G�n�ral JavaScript
    R�ponses: 16
    Dernier message: 17/03/2006, 17h24
  3. [FLASH MX2004] Javascript --> Flash
    Par bomber dans le forum Flash
    R�ponses: 5
    Dernier message: 03/03/2005, 16h25
  4. [FLASH MX 2004] Communication javascript--flash
    Par meslaey dans le forum Flash
    R�ponses: 4
    Dernier message: 28/06/2004, 09h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo