A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: CS4 Code not working in movieclip

  1. #1
    Member
    Join Date
    Apr 2009
    Posts
    62

    CS4 Code not working in movieclip

    Hello,
    I can place the following code on a movieclip:
    PHP Code:
    onClipEvent(load) {
        
    gravity 0.2;
        
    yspeed 0;
        
    speed 2;
    }
    onClipEvent(enterFrame) {
        if(
    flipped) {
            
    this._xscale = -this._xscale;
            
    flipped false;
        }
        if(
    this._x >= 763 or this._x <= 37) {
            
    flipped true;
            
    speed = -speed;
        }
        if(!
    _parent.bricks.hitTest(_x+_width/2_y+_height/4true)) {
            
    _x += speed;
        }
        
    yspeed += gravity;
        while(
    _parent.bricks.hitTest(_x_y+_height/2true)) {
            
    _y--;
            
    yspeed 0;
            
    jumping 0;
        }
        if((!
    _parent.bricks.hitTest(_x_y+_height/2+1true)) or (yspeed<0)) {
            
    _y += yspeed;
        } else {
            
    yspeed 0;
            
    jumping 0;
        }

    And it'll work fine, however if I place it like this on a frame in the movieclip:
    PHP Code:
    this.onLoad = function() {
        
    gravity 0.2;
        
    yspeed 0;
        
    speed 2;
    }
    this.onEnterFrame = function() {
        if(
    flipped) {
            
    this._xscale = -this._xscale;
            
    flipped false;
        }
        if(
    this._x >= 763 or this._x <= 37) {
            
    flipped true;
            
    speed = -speed;
        }
        if(!
    _parent.bricks.hitTest(_x+_width/2_y+_height/4true)) {
            
    _x += speed;
        }
        
    yspeed += gravity;
        while(
    _parent.bricks.hitTest(_x_y+_height/2true)) {
            
    _y--;
            
    yspeed 0;
            
    jumping 0;
        }
        if((!
    _parent.bricks.hitTest(_x_y+_height/2+1true)) or (yspeed<0)) {
            
    _y += yspeed;
        } else {
            
    yspeed 0;
            
    jumping 0;
        }

    It doesn't work

    Any help would be greatly appreciated since this is for a school project due in a week...
    Check out my firefox theme "PacStrata" here

  2. #2
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Are using an Actionscript 3.0 because your code will only work for a Actionscript 2.0 file.

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    check the variables in your output for both versions. See what's different.

    gparis

  4. #4
    Member
    Join Date
    Apr 2009
    Posts
    62
    I'm using Actionscript 2. I also found none of my onLoad code is executing, same with the onEnterFrame code. However if I add trace('Working') under the onEnterFrame section, it works, but no other code will.
    Check out my firefox theme "PacStrata" here

  5. #5
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Is this part necessary “this.onLoad = function()”. You only need to define the variables, so having the following code below would just be fine.
    Code:
    var gravity = 0.2; 
    var yspeed = 0; 
    var speed = 2;

  6. #6
    Member
    Join Date
    Apr 2009
    Posts
    62
    Hmm...good point..."this.onLoad = function()" isn't necessary after all. I'll try without that.
    It'll probably work since using the "this.onLoad = function()" didn't give the variables their required values...
    Check out my firefox theme "PacStrata" here

  7. #7
    Member
    Join Date
    Apr 2009
    Posts
    62
    Tried it and while it works...the movements are really messed up
    Check out my firefox theme "PacStrata" here

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