A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Multiple AttachMovie/onEnterFrame = function() {

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    7

    Question Multiple AttachMovie/onEnterFrame = function() {

    I'm working on a arcade style game where the player collects items for points and a different item for oxygen. The problem I have encountered is that when I put the code only one of the item functions the other doesn't even appear. I've done some research and discovered you can only have one onEnterFrame function and I think only one attachmovie function... How would I go about to combining or making the code work. BTW I'm working with actionscript 2.0. Thanks a million for helping!

    PHP Code:
    _root.attachMovie("item""collect"9,{_x:100_y:100});
    collect._x random(300);
    collect._y random(300);

    soScores SharedObject.getLocal("flashcookie");
    var 
    score 0;
    if (
    soScores.data.highScore != null) {
        
    highScore soScores.data.highScore;
    }
    onEnterFrame = function() {
        if(
    _root["collect"].hitTest(_root.player)) {
        
    removeMovieClip(["collect"]);
        
    collectitem.start(0,1);
        
    score+=1000;
        
    _root.attachMovie("item""collect"9,{_x:100_y:100});
        
    collect._x random(300);
        
    collect._y random(300);
    }
        else if (
    score highScore) {
            
    highScore score;
            
    soScores.data.highScore highScore;
        }
    }



    _root.attachMovie("oxygen""oxygen"9,{_x:100_y:100});
    oxygen._x random(300);
    oxygen._y random(300);

    onEnterFrame = function() {
        if(
    _root["oxygen"].hitTest(_root.player_1)) {
        
    removeMovieClip(["oxygen"]);
        
    oxygencollect.start(0,1);
        
    _root.oxygenbar.prevFrame ();
        
    _root.attachMovie("oxygen""oxygen"9,{_x:100_y:100});
        
    oxygen._x random(300);
        
    oxygen._y random(300);
        }


  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    I think the problem is that you are attaching both objects at same depth:

    _root.attachMovie("oxygen", "oxygen", 9,{_x:100, _y:100});

    Number 9 here is depth. If you try to put another movieclip at same depth, it will replace old one. Try using different depth for oxygen.

    As for enterFrame problem, you do not need 2 of them, just copy the code from second enterFrame function and paste it into first one. It would look like this:

    //check for collect movieclip
    if(){
    }
    //check for oxygen mc
    if(){
    }

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    7
    Wow, thanks tonypa, now the code works flawlessly and I learned something new! Cheers.

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