A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: problem with onPress

  1. #1
    Member
    Join Date
    Feb 2004
    Posts
    31

    problem with onPress

    Why does the onPress doesn't work here. How can i solve this problem.
    thx for your help. greetings

    code:
    	for (j=0; j<rest; j++) {
    _tl.attachMovie("thumb_mc", "thumb"+g, g+100);
    d = eval("_tl.varReceiver.thumb"+g);
    _tl["thumb"+g].loadMovie(d);
    _tl["thumb"+g].onPress = function(){
    trace("clicked");
    }
    _tl["thumb"+g]._x = x;
    _tl["thumb"+g]._y = y;
    g++;
    x += 50;
    }


  2. #2
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    Had to take out your loadMovie, I was getting errors, but the onPress worked for me....I dunno.

    Adam

  3. #3
    ActionScript Insomniac
    Join Date
    Jan 2003
    Location
    43d03.21'N, 89d23.65'W
    Posts
    1,173
    loadMovie takes a string argument. eval gives you a movieclip reference, rather than a string. This *might* get autoconverted to a string, but it's not a good way to set it up.

    loadMovie replaces the original movie clip. In doing so, it erases the onPress method. Even though the call to loadMovie comes before the assignment to onPress, loadMovie takes a while to happen, and is completed after the assignment of onPress. Make in inner movie clip to call loadMovie on, and an outer clip to have the onPress method (should be a familiar pattern by now....)

  4. #4
    Unknowable Donkey of Spong Crash Raindog's Avatar
    Join Date
    Oct 2002
    Posts
    148
    You could replace this:

    code:
    d = eval("_tl.varReceiver.thumb"+g);



    with this:
    code:


    d=_tl.varReceiver["thumb"+g];



    Putting the "thumb"+g into square brackets straight after an object name (notice no dot) forces flash to recognize it as a variable or object name and so it reacts accordingly.

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