A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS2: Move Object Codes to a layer

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    4

    AS2: Move Object Codes to a layer

    Hi, im a newbie when it comes to Flash, I just recently started learning it, I found This Tutorial on youtube About how to make a platform game its here : https://www.youtube.com/watch?v=NTuh...NVFcoPT3UYHqmA . The Tutorial is good, but i was wondering how do i move the codes from the object character "char" to a New seperate Layer?... Ive been fiddling around the codes but i cant seem to get it to work, my goal is to put all the codes in a Separate Layer, can you help me how to do that?..Any help will be much appreciated


    Code for the character:

    onClipEvent (load) {
    var ground:MovieClip = _root.ground;
    var grav:Number = 0;
    var gravity:Number = 2;
    var speed:Number = 7;
    var maxJump:Number = -12;
    var touchingGround:Boolean = false;
    }
    onClipEvent (enterFrame) {
    _y += grav;
    grav += gravity;
    while (ground.hitTest(_x, _y, true)) {
    _y -= gravity;
    grav = 0;
    }
    if (ground.hitTest(_x, _y+5, true)) {
    touchingGround = true;
    } else {
    touchingGround = false;
    }
    if (Key.isDown(Key.RIGHT)) {
    _x += speed;
    }
    if (Key.isDown(Key.LEFT)) {
    _x -= speed;
    }
    if (Key.isDown(Key.UP) && touchingGround) {
    grav = maxJump;
    }
    if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
    _x -= speed;
    }
    if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
    _x += speed;
    }
    if (ground.hitTest(_x, _y-(height), true)) {
    grav = 3;
    }
    }

  2. #2
    Member
    Join Date
    Apr 2014
    Posts
    63
    I think for a response you will have to elaborate. For example, where is this code? is it on your main timeline? If it's on a keyframe then the scripting should apply to objects within layers that are in your timeline. So when you say you want to move to a different layer then need some explanation on that.

  3. #3
    Registered User
    Join Date
    Sep 2014
    Posts
    4
    This code is in my main timeline inside a movieclip called "char". now i have a layer specificaly for actionscripts called "AS". now i want to move the actionscripts from my "char" to this layer called "AS", i have no idea how, ive tried replacing "onClipEvent (enterFrame)" with "char.onEnterframe = function" and fiddling around with the x and y axis, but cant get it to work

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Obviously remove the code from char, then place it in your AS layer.

    PHP Code:
    var ground:MovieClip _root.ground;
    var 
    grav:Number 0;
    var 
    gravity:Number 2;
    var 
    speed:Number 7;
    var 
    maxJump:Number = -12;
    var 
    touchingGround:Boolean false;

    char.onEnterFrame = function()
    {
        
    char._y += grav;
        
    grav += gravity;
        while (
    ground.hitTest(char._xchar._ytrue))
        {
            
    char._y -= gravity;
            
    grav 0;
        }
        if (
    ground.hitTest(char._xchar._y 5true))
        {
            
    touchingGround true;
        }
        else
        {
            
    touchingGround false;
        }
        if (
    Key.isDown(Key.RIGHT))
        {
            
    char._x += speed;
        }
        if (
    Key.isDown(Key.LEFT))
        {
            
    char._x -= speed;
        }
        if (
    Key.isDown(Key.UP) && touchingGround)
        {
            
    grav maxJump;
        }
        if (
    ground.hitTest(char._x + (char._width 2), char._y - (char._height 2), true))
        {
            
    char._x -= speed;
        }
        if (
    ground.hitTest(_x - (char._width 2), char._y - (char._height 2), true))
        {
            
    char._x += speed;
        }
        if (
    ground.hitTest(char._xchar._y - (height), true))
        {
            
    grav 3;
        }
    }; 
    I'm not sure if the last (height) is meant to be (char._height) or not, i just copied your code over.

    Soemtimes it's a whole lot easier for us if you attach the fla, saves us having to try and remake your file.

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