Skip to main content
Known Participant
January 30, 2013
Question

Invert Y axis

  • January 30, 2013
  • 1 reply
  • 1551 views

Hi everyone!

For some reason, the Y axis in flash is inverted, meaning positive values point down.

Is there anyway to flip it, so positive values will point up, like in every normal coordinate system? it's very wierd working like that...

Thank you!

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
January 30, 2013

It's likely because by default everything registers from the top left corner of the stage... if the values were inverted as you ask, then you'd usually be dealing with negative y values and would probably be asking for that to be changed.

Sason922Author
Known Participant
January 30, 2013

Yeah I realise that that top left corner is the default zero point for the axis, I ask if there is anyway to change it, or is it a fixed feature that can't be changed?

Inspiring
January 30, 2013

You could program a workaround for your needs:

say you have a MovieClip with As-Linkage "MC" in your Library;

write a class MC.as :

package

{

    import flash.display.MovieClip;

    import flash.events.Event;

    public class MC extends MovieClip

    {

        private var _numValue:Number;

        private var _stageHeight:Number;

        public function MC(_stH:Number)

        {

            // constructor code

            _stageHeight = _stH;

        }

        public function set y2(_yy:Number):void

        {

            this._numValue = _stageHeight - _yy;

            this.y = this._numValue;

        }

        public function get y2():Number

        {

            this._numValue = _stageHeight - this.y;

            return this._numValue;

        }

    }

}

Then in your Flash File write sth like:

import flash.display.MovieClip;

import flash.events.Event;

var _mc:MC = new MC(stage.stageHeight);

_mc.y2 = 0;

addChild(_mc);

addEventListener(Event.ENTER_FRAME, moveUp);

function moveUp(e:Event):void{

   //this moves the MovieClip upward from the bottom left corner to the top left corner

    _mc.y2 +=1;

}

-> you will notice your MovieClip has now a property y2, that behaves just like an inverted y-property

It will also work with a TweenFramework like TweenMax:

//this moves the MovieClip upward from the bottom left corner to the top left corner

TweenMax.fromTo(_mc,3,{y2:0},{y2:400});