Member 68
24 entries
38262 views

 RSS
Contributor to project:
Design Media Arts at UCLA
Joe Chunzu Liao (M, 34)
Hong Kong, HK
Immortal since Mar 29, 2007
Uplinks: 0, Generation 1

joe.liao.info
  • Affiliated
  •  /  
  • Invited
  •  /  
  • Descended
  • Recently commented on
    From adam
    Who gets to go? part 2
    czliao’s project
    Design Media Arts at UCLA
    In the 1970s space colonies were considered to be a viable alternative to a life restricted to planet Earth. The design of cylindrical space...
    Now playing SpaceCollective
    Where forward thinking terrestrials share ideas and information about the state of the species, their planet and the universe, living the lives of science fiction. Introduction
    Featuring Powers of Ten by Charles and Ray Eames, based on an idea by Kees Boeke.
    From czliao's personal cargo

    I | O - interaction
    Project: Design Media Arts at UCLA
    The Arduino–Flash communication tutorial can be found here.

    While the code for the flash side (action scripts) is as follow:
    ///////////////////////////
    ——————————-
    fscommand("fullscreen", "true");

    Mouse.hide();
    //———————————————————————————————————— Basic Arduino

    import Arduino;

    var port:Number = 5331; // What socket port are we configured to use?
    // See the net_port entries from serproxy.cfg

    // Create a custom object from Flash's XMLSocket
    var a:Arduino = new Arduino(port);


    //———————————————————————————————————— Listeners


    // You can trigger custom actions by adding listners to the Arduino object. For example, you can setup your
    // ActionScript code to run a setup function when Flash successfully connects to the socket listener

    aListener = new Object();

    aListener.onConnect = function() {
    trace("hello world");
    }

    aListener.onReceiveData = function(evtObj:Object){
    //Store the received data in a string
    var str = evtObj.data
    trace("Arduino says — " + str);

    if (vid1._currentframe != 1)
    {
    trace("key pressed1");
    vid1._alpha = 0;
    vid1.gotoAndStop(1);
    vid2.play();
    } else {
    trace("key pressed2");
    vid1._alpha = 100;
    vid1.play();
    vid2.gotoAndStop(1);
    }
    //Tests for a particular message from Arduino, and acts accordingly
    /*if (str == "switchOff") {
    vid1.play();
    vid1._alpha=100;
    vid2.gotoAndStop(1);
    }
    else if (str == "switchOn") {
    vid2.play();
    vid1._alpha=0;
    vid1.gotoAndStop(1);
    }*/
    }

    // Binds your custom listeners to the Arduino object (a)
    a.addEventListener("onConnect",aListener);
    a.addEventListener("onReceiveData",aListener);

    //———————————————————————————————————— That's all!


    //keyboard control

    var keyListener:Object = new Object();
    keyListener.onKeyDown = function() {
    if (Key.isDown(Key.SPACE)) {
    if (vid1._currentframe != 1) {
    trace("key pressed1");
    vid1._alpha = 0;
    vid1.gotoAndStop(1);
    vid2.play();
    } else {
    trace("key pressed2");
    vid1._alpha = 100;
    vid1.play();
    vid2.gotoAndStop(1);
    }
    }
    }

    Key.addListener(keyListener);
    ——————————-
    ////////////////////////////
    There're 2 major problems that I faced:

    1,) using netstream functions, you cannot loop video's seamlessly, because they'll always have to reload the video when it ended before it could be played again, so there'll be about half a second of a lag, even when the file is stored locally.

    2.) The arduino communication is based on a .as file stored outside of this code (that's why this is not long at all), however, when I started programming, I chose to try out Action Script 3 — the result is that it wouldn't work because the external .as file is written in AS2 and many syntax were changed only slightly — much enough for me to not be able to translate that whole page into AS3 at that time. Thus, I translated my AS3 code back into AS2, saved it as a AS2 file, it works.


    Sun, Jun 24, 2007  Permanent link

    Sent to project: Design Media Arts at UCLA
      RSS for this post
    Add comment
      Promote
      
      Add to favorites
    Create synapse
     
     
          Cancel