Weird Variable Problem

March 14th, 2010
  • What I'm trying to do is very simple. I have no idea why this is not working. All I am trying to do is move a movieclip by using a variable.

    This does work:

    onClipEvent(enterFrame) {
    _root.background.picture._x += .5;
    }


    It moves the MC .5 pixels everytime the playhead enters the frame.

    Now, I'm trying to simply change the .5 to a _global variable that I have. So I'm using:

    onClipEvent(enterFrame) {
    _root.background.picture._x += _global.xspeed;
    }


    For whatever reason, this causes my MC to disappear. I've even traced the _global.xspeed to see that the variable is even there and it is. The only thing that I can possibly see is that when I traced the variable _global.xspeed, the first thing for a nano second was "undefined". After that it was all numbers.

    How can I fix this? Is there a way to say "if _global.xspeed is a number then do this else don't do anything"?


  • I think I found some code to make it work. In my output panel it looks right, but still nothing is being displayed. I don't get this.

    Here's the code I use:

    onClipEvent(enterFrame) {
    if (isNaN(_global.xspeed)) {
    //nothing
    }
    else{
    _root.background.picture._x += _global.xspeed;
    }

    //trace(_root.background.picture._x+" and "+_global.xspeed);

    }


  • I got it! I have no idea why this works, but it does:


    onClipEvent(enterFrame) {
    xyz = (_global.xspeed/1);

    if (isNaN(xyz)) {
    //nothing
    }
    else{
    _root.background.picture._x += xyz;
    trace(_root.background.picture._x+" and "+ xyz);
    }

    }


    I just added that bit in red, and it did the trick. Very strange I think.







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Weird Variable Problem , Please add it free.