A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: RETURN doesn´t work within a function setInterval ?

  1. #1
    Peace and good Vibes Pippomusic's Avatar
    Join Date
    Jan 2002
    Location
    Rome, Italy
    Posts
    169

    RETURN doesn´t work within a function setInterval ?

    Hello...

    I found out a weird behaviour which i cannot explain....

    If I have a function, with a setInterval within, and a "return" statement within the setInterval... return does not work!!!

    I cannot find an easy workaround and I am a bit stuck... found a solution but with too many if/else... I dont like it much...

    Did this happen to you too?

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    What do you mean? you'll have to give an example

  3. #3
    Peace and good Vibes Pippomusic's Avatar
    Join Date
    Jan 2002
    Location
    Rome, Italy
    Posts
    169
    ok...

    function hello() {
    var int = setInterval(function(){
    return "hello";
    clearInterval(int);
    }, 1000);
    }

    var pippo = hello();

    trace(pippo);

    returns undefined!!!!! but it should be "hello" right?
    the function breaks, but i cannot send out results with a return...

  4. #4
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    hello doesnt return anything, only your setinterval function does. That return goes nowhere and happens 1 second after hello was run. What pippo gets is the immediate return of the hello call which is nothing

  5. #5
    Peace and good Vibes Pippomusic's Avatar
    Join Date
    Jan 2002
    Location
    Rome, Italy
    Posts
    169
    Yes.... I get it now....
    thenk you....

    Maybe you can help me on something sinocular....

    I am stuck in this big, but maybe very silly problem...
    I need to retrieve the absolute path to an object instance and convert it to a string...
    Let´s say I have an instance:

    myObj = new Object();

    Then I need to retrieve the absolute path to myObj (i.e. "_level2.myObj").
    I cannot see any command to do that... for a MovieClip I could use the _target property, but for an Object I really got no idea...
    I need that path to send it to a host application with an FSCommand...
    Anything I try to get out from an object instance is always [Object Object]...

    Got any clue?


    thank you
    Pippo

  6. #6
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    you really dont have paths to objects... you do, but not static paths for the objects themselves. Objects are entities that have no 'footing' in any movieclip as another movieclip would. Any given movieclip has a movieclip, beit another movieclip or _root, which it exists. If its there, its there and no where else. Objects, on the otherhand exist 'theoretically' in memory. You can create them in a movieclip but they arent really in that movieclip. All you have is a reference to that object in memory in that movieclip. You could just as well reference that object in another movieclip, delete the orginal reference and now your object exists in THAT movieclip. Ex:

    Code:
    this.one_mc.obj = new Object();
    this.two_mc.obj = this.one_mc.obj;
    delete this.one_mc.obj;
    The object now in two_mc is the same object created in one_mc, but no longer exists in one_mc because it was deleted. Now it only exists in two_mc... and at one point in time, it existed in both. If generic objects were to have a built in _target property, what would it say if it existed in more than one movieclip... or in other objects for that matter? It wouldnt know what to say. In fact, there is no real way to tell aside from cycling through all your movieclips and objects in your movie and finding out where that object exists by checking each object in those objects for equality with the object in question.

    Solution? You'll have to hardcode it in yourself.

    myObj = new Object();
    myObj._target = this._target + "/myObj";

  7. #7
    Peace and good Vibes Pippomusic's Avatar
    Join Date
    Jan 2002
    Location
    Rome, Italy
    Posts
    169
    That was really clear...
    Thanks a lot Senocular you are very good at explaining....

    I could probably trick with a single MovieClip just as a reference holder, thus i can use a mc._target + the id of the object....

    Thanks again,
    pippo

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