What is the difference between ax = 100; ay = 100 and a.move (100 100)?

What is the difference between using

a.x = 100;
a.y = 100;

      

and

a.move(100,100);

      

in actionscript 3 / Flex?

Best regards,
Artem

0


a source to share


6 answers


What? If we knew what "a" is, then it would be easier to answer. Ax or ay will normally specify the coordinates for the top-left corner of an object (like Button) in its parent (like Canvas).

If 'a' was a Button then setting .x and .y or setting move (x, y) will do the same.



Check documents. 'Moves the component to the specified position in its parent. Calling this method is exactly the same as setting the x and y properties of the component.

http://livedocs.adobe.com/flex/3/langref/index.html , it's under UIComponent.

+2


a source


In general: a method call binds what you do just by selecting the member variables, no.



As ChrisF said, there could also be a difference where the gouge moves to absolute coordinates and the method call moves relative to the current position. I tried to find the link but couldn't find it.

+2


a source


Just guessing (I don't know ActionScript), but I would think that

a.x = 100;
a.y = 100;

      

would set (100, 100) and

a.move(100,100);

      

will add (100,100) to the current value of a. However, in light of the accepted answer, it looks like it does the same. Although the following advice still holds true:

Have you tried the latter for different initial values ​​(0, 0), (100, 100), (23, 42), etc. and checked what's going on?

If you are not sure that you will check something, you will not break anything, and even at first you will not be able to make mistakes, it can teach you something.

I quickly looked through the documentation but couldn't do anything about it. I find it best to create multiple test cases to explore what each approach does.

+1


a source


ActionScript properties can in fact be backed up by methods - called getter / setter pairs. So when you set the ax = 100 property, there is very likely code that is being executed to deal with the consequences of changing that property. (Without knowing what type of a is here, it’s impossible to know for sure - indeed, it’s impossible to know at all, and you should not assume that you are)

Beware of one thing here: calling one method like a.move (x, y) can be very different from calling two different setter methods for ax = q and ay = r It all depends on how the class you are using is implemented. For this reason, many Flex frame classes (all?) Use the invalidateProperties () ... commitProperties () pattern to ensure that all property changes are coordinated through a single checkpoint.

+1


a source


Here's an example of when to use move:

If you are overriding a method updateDisplayList()

in a custom component, you must call the method move()

, not set properties x

and y

. The difference is that the method move()

changes the location of the component and then dispatches an event move

when the method is called, while setting properties x

and y

changes the location of the component and dispatches the event on the next screen refresh.

+1


a source


[WINDOWS_USER_PROFILE_PATH]\Local Settings\Application Data\Adobe\Flash[version]\en\Configuration\Classes

      

Always look here to know for sure. If you mean UIControl take a look at[PATH_ABOVE]\mx\core\UIObject.as

And you will see the difference:

function move(x:Number, y:Number, noEvent:Boolean):Void
{
    //trace("UIObject.move " + this + " -> (" + x + ", " + y + ")");
    var oldX:Number = _x;
    var oldY:Number = _y;

    _x = x;
    _y = y;

    if (noEvent != true)
    {
        dispatchEvent({type:"move", oldX:oldX, oldY:oldY});
    }
}

      

So, the correct answer is: after assigning new coordinates, this method dispatches the "move" event specified by the old coordinates. It's all.

PS: if you are using another Flash compiler - just find its class definitions somewhere on your machine ...

0


a source







All Articles