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 actif
    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
    Points : 219
    Points
    219
    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 ++
    Goah Sha Kree

  2. #2
    Membre régulier Avatar de Iori Yagami
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    107
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 107
    Points : 88
    Points
    88
    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 actif
    Profil pro
    Inscrit en
    Février 2007
    Messages
    265
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 265
    Points : 284
    Points
    284
    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