Results 1 to 6 of 6

Thread: Javascript communicating with flash?

  1. #1
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript communicating with flash?

    hi guys

    basically i need to know how to get the position of the y-coordinate and how far its travelled down the height of a flash file..
    I'm aiming to produce something like this..

    here
    it wont work in Firefox by the way.. I'm not sure why..

    but if at all possible could some one just set me on the right path of what I should be coding and where/how I should be directing it..
    maybe some code to help me too?

    thanks

  2. #2
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    does no1 have any ideas guys?!

  3. #3
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    I'm pretty sure you can write "flash code" in your flash program if that would solve your problem.
    Trinithis

  4. #4
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yea...there is that part to it as well, but after having broken down the example I linked to, it says it uses javascript to get the measurements of the page and then feeds theses into flash so it knows which frame to play based on the javascript.. the problem is I'm not a very good (at all) javascripter, and I don't really understand all this kind of thing, so what I'm really hoping for is some terms to search for to set me on my way to learning what i need for this project.. the possibility of code, i was hoping would have been as an example so i knew what was doing what...

    here is some of the files I've taken from the original I'm trying to re create, the file named 'javascript.js' is the one with lots of javascript which I don't understand in much detail...

    sorry, I know this is kinda long, but its for a uni project, and the tutors were a little vague.. so just some kinda path to set off on?

  5. #5
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    anyone?

  6. #6
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi there, possibly this may be useful.....the example re coke can is a flash file consisting of 13 frames. Each frame shows the can in an increasingly crushed state. There is a javascript function within the html called tratascroll (this particular example is spanish!!) whenever the user scrolls down the html page the function is called:
    There is an predefined array consisting of 13 positions
    the variable t is calculated by subtracting the offsettop for the coke object from the body scrolltop.
    The conditional statement is checking to see if t is between any of the array values. ie if it is >= 70 and <=80 (n=1) ie has the user scrolled enough to initiate another frame being played. The case statement is setting up a parameter which is passed back to the flash file "som1" to "som4" case 1 and "som4" to "som6" for case 2.
    The frame variable is then incremented by 1 for each execution of the for loop.
    The important statements where you are concerned are the
    document.all['sky'].setVariable('idSom', idSom); This is passing a value to the flash variable idSom. (The actual sound played for each frame)
    and
    document.all['sky'].FrameNum = intFrame;
    This is setting the actual frame to be played.
    I haven't fully deconstructed the html/javascript code but hopefully this is a start. Havent had time to look at your sample code yet, but if I get the chance I'll get back to you!!
    Regards!

    This is a copy relevant code of the javascript from the sample page
    var intFrame = 0;
    var arrPos = new Array(0, 75, 80, 95, 119, 167, 231, 284, 320, 359, 406, 455, 489); // Posicoes da lata

    function trataScroll(e) {
    var t = parseInt((document.body.scrollTop - document.all['bannerCoke'].offsetTop));

    for (n in arrPos) { // Verificamos cada posicao
    if (t >= arrPos[n] && t < arrPos[parseInt(n) + 1] && n > intFrame - 1) {
    intAtual = parseInt(n) + 1;
    intOffset = intAtual - intFrame;

    // Verificamos o som a ser tocado
    switch(intOffset) {
    case 1:
    idSom = 'som' + parseInt((Math.random() * 3) + 1);
    break;
    case 2:
    idSom = 'som' + parseInt((Math.random() * 2) + 4);
    break;
    default:
    idSom = 'som6';
    break;
    }

    // Define som
    document.all['sky'].setVariable('idSom', idSom);

    intFrame = intAtual;
    document.all['sky'].FrameNum = intFrame;
    }
    }
    }

    // Controle de Scroll
    window.onscroll = trataScroll;

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •