A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: how do I pass variables from function to function?

  1. #1
    Junior Member
    Join Date
    Apr 2006
    Posts
    4

    how do I pass variables from function to function?

    hello, basically I have two functions.
    Function A has a loop in it and Function B has a loop inside as well. What I want to do is pass the variable from function A's loop to Function B's loop.

    I've tried using return variable; but that does not seem to be doing it right.
    any ideas?

    thank you in advance.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You need to be more specific and show us your code.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Apr 2006
    Posts
    4
    Alright here's the code:

    First part of the code, this part plays the videos.

    var xml:XML = new XML();
    xml.ignoreWhite = true;


    xml.onLoad = function(i) {

    var nodes = this.firstChild.childNodes;
    for(var i=0; i<nodes.length; i++) {
    list.addItem(nodes[i].attributes.desc, nodes[i].attributes.flv);

    }

    vid.play(list.getItemAt(0).data)
    list.selectedIndex = 0;

    }

    xml.load("playlist.xml");

    var lList:Object = new Object();
    lList.change = function() {
    vid.play(list.getItemAt(list.selectedIndex).data);
    count = list.selectedIndex;

    }

    list.addEventListener("change", lList);

    var vidList:Object = new Object();
    var count:Number = 0;

    vidList.complete = function() {
    if(seq.selected) {
    if(count == list.length-1){
    count = 0;

    }
    else {
    count++;

    }

    }
    else {
    var temp = count;
    while(temp == count) {
    count = Math.floor(Math.random()*list.length);
    }
    }

    vid.play(list.getItemAt(count).data);
    list.selectedIndex = count;
    list.getSelectedIndex();

    return count;
    }

    vid.addEventListener("complete", vidList);
    trace(count);

    second part of the code which plays the slideshows

    delay = 3000;
    //-----------------------
    function loadXML(loaded) {

    if (loaded) {

    xmlNode = this.firstChild;
    image = [];
    image3 = [];
    messages = [];
    total = xmlNode.childNodes.length;


    for (var q=0; q<total; q++) {

    image[q] = xmlNode.childNodes[count].childNodes[1].childNodes[q].firstChild.nodeValue;
    image3[q] = xmlNode.childNodes[count].childNodes[2].childNodes[q].firstChild.nodeValue;
    messages[q] = xmlNode.childNodes[count].childNodes[3].childNodes[q].firstChild.nodeValue;


    }

    firstImage();

    } else {

    content = "file not loaded!";

    }

    }


    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("playlist2.xml");

    p = 0;

    function nextImage() {

    if (p<(total-1)) {

    p++;

    if (loaded == filesize) {

    picture2._alpha = 0;
    picture2.loadMovie(image[p], 1);
    picture3._alpha = 0;
    picture3.loadMovie(image3[p], 1);
    desc_txt2.text = messages[p];
    slideshow();

    }

    }

    }

    function firstImage() {

    if (loaded == filesize) {

    picture2._alpha = 0;
    picture2.loadMovie(image[0], 1);
    picture3._alpha = 0;
    picture3.loadMovie(image3[0], 1);
    desc_txt2.text = messages[0];
    slideshow();

    }

    }

    function slideshow() {

    myInterval = setInterval(pause_slideshow, delay);

    function pause_slideshow() {

    clearInterval(myInterval);
    if (p == (total-1)) {

    p = 0;
    firstImage();

    } else {

    nextImage();

    }

    }

    }

    so basically I want the slideshow playback to be synchronized with the video playback.

    Here's my XML to make things clearer:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <images>
    <items>
    <channel1>
    <video desc="Prisoner of Azkaban" flv="flv/azkaban.flv" item="2"/>
    </channel1>

    <channel2>
    <images>images/ch2/ss310.jpg</images>
    <images>images/ch2/ss001.jpg</images>
    <images>images/ch2/ss002.jpg</images>

    </channel2>
    <channel3>
    <images>images/ch3/ss308.jpg</images>
    <images>images/ch3/ss007.jpg</images>
    <images>images/ch3/ss008.jpg</images>
    </channel3>
    <channel4>
    <messages>Item 1 message 1</messages>
    <messages>Item 1 message 2</messages>
    <messages>Item 1 message 3</messages>
    </channel4>

    </items>

    <items>

    <channel1>
    <video desc="X Men 3" flv="flv/xmen3.flv" item="0"/>
    </channel1>

    <channel2>
    <images>images/ch2/ss305.jpg</images>
    <images>images/ch2/ss003.jpg</images>
    <images>images/ch2/ss004.jpg</images>

    </channel2>
    <channel3>
    <images>images/ch3/ss309.jpg</images>
    <images>images/ch3/ss009.jpg</images>
    <images>images/ch3/ss010.jpg</images>
    </channel3>
    <channel4>
    <messages>Network Casting Test</messages>
    </channel4>

    </items>

    <items>

    <channel1>
    <video desc="Fantastic Four" flv="flv/fantastic4.flv" item="1">
    </channel1>
    <channel2>
    <images>images/ch2/ss306.jpg</images>
    <images>images/ch2/ss005.jpg</images>
    <images>images/ch2/ss006.jpg</images>
    </channel2>
    <channel3>
    <images>images/ch3/ss307.jpg</images>
    <images>images/ch3/ss011.jpg</images>
    <images>images/ch3/ss012.jpg</images>
    </channel3>
    <channel4>
    <messages>Hello, testing testing</messages>
    </channel4>

    </items>




    </images>

    What I want to do is play the 'items' as a set, meaning when the video starts playing channel 2-4 will start playing from their individual loops. When the video finishes, it will move on to the second set of items and the cycle repeats. When it reaches the last set of 'items' and finishes playing it will loop back to the first set of 'items' again.

    I've got channels 2-4 looping on their own, but they won't change to the second set of 'items' when the video changes, so I was thinking if I could use the 'count' variable which is the index of the currently playing video to control channel 2-4.

    Thank you

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    What is seq? nowhere defined.

    if (seq.selected)
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Junior Member
    Join Date
    Apr 2006
    Posts
    4
    seq.selected is to check whether the combo box named seq is selected or not
    cause there's an option of playing the videos sequentially or randomly.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center