a的区别是什么?x = 100;一个。y = 100 a移动(100,100)?

时间:2022-06-07 03:14:19

What is the difference between using

使用的区别是什么

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

and

a.move(100,100);

in actionscript 3 / Flex ?

在actionscript 3 / Flex中?

Best regards,
Artem

最好的问候,Artem

6 个解决方案

#1


2  

What is a? If we knew what 'a' is then it would make it simpler to answer. The a.x or a.y would normaly specify the coordinates for the top left hand corner of the object (say Button) in its parent (say Canvas).

一个是什么?如果我们知道a是什么,那么答案就会更简单。一个。x或。y将在其父(比如画布)中指定对象左上角的坐标(比如按钮)。

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

如果“a”是一个按钮,那么设置.x和.y或设置move(x, y)也会起到同样的作用。

Check the docs out 'Moves the component to a specified position within its parent. Calling this method is exactly the same as setting the component's x and y properties. '

检查文档是否将组件移动到父组件的指定位置。调用此方法与设置组件的x和y属性完全相同。”

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

这在http://livedocs.adobe.com/flex/3/langref/index.html的UIComponent之下。

#2


2  

In general: calling a method communicates what you're doing, just poking member variables doesn't.

一般来说:调用一个方法会传递您正在做的事情,而只是戳成员变量则不会。

As ChrisF said, there might also be a difference where poking moves to absolute coordinates, while the method call moves relative to the current position. I tried looking up a reference, but didn't find one.

正如ChrisF所说,在将移动到绝对坐标时,也可能有不同,而方法调用相对于当前位置的移动。我试着找一份推荐信,但没有找到。

#3


1  

Just guessing (I don't know actionscript) but I would have thought that

只是猜测(我不知道actionscript)但是我想过

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

would set a to be (100, 100), while

将a设为(100,100

a.move(100,100);

would add (100,100) to the current value of a. However, in light of the accepted answer it appears it does the same. Though the following advice still holds:

将(100,100)加到a的当前值,但是,根据所接受的答案,它似乎是一样的。尽管以下建议仍然有效:

Have you tried the latter for different initial values of a (0, 0), (100, 100), (23, 42) etc. and checked what happens?

对于a(0,0)、(100,100)、(23,42)等不同的初始值,你是否尝试过后一种方法?

If you're not sure about something test it out - you're not going break anything and it even getting it wrong first time can teach you something.

如果你对某件事不确定,那就试一试——你不会打破任何东西,即使第一次出错也能教会你一些东西。

I did a quick search for some documentation, but wasn't able to turn anything up. I think your best bet is to generate some test examples to explore what each approach does.

我快速搜索了一些文档,但是什么都找不到。我认为您最好的方法是生成一些测试示例来探究每种方法的作用。

#4


1  

ActionScript properties can in fact, be backed by methods - so called getter/setter pairs. So when you set the property a.x = 100, there's quite likely code that is executing to deal with the implications of that property change. (Not knowing what type a is here, it's not possible to know for sure - indeed, it's never possible to know in general, and you shouldn't assume that you do)

ActionScript属性实际上可以由方法支持——所谓的getter/setter对。当你设置属性a。x = 100,有很可能的代码正在执行以处理该属性变化的影响。(不知道a在这里是什么,这是不可能确定的——事实上,通常不可能知道,而且你不应该假设你是这样做的)

Be careful about one thing here: calling a single method such as a.move(x,y) could be quite different from calling two the two separate setter methods behind a.x = q and a.y = r It all depends on how the class you're using has been implemented. For this reason, many Flex framework classes (all?) use the invalidateProperties() ... commitProperties() pattern to ensure that all property changes are coordinated through a single control point.

这里要注意一件事:调用单个方法(如a.move(x,y))可能与调用两个位于a后面的独立setter方法非常不同。x = q和a。这完全取决于您使用的类是如何实现的。由于这个原因,许多Flex框架类(全部?)都使用invalidateProperties()……commitProperties()模式,以确保通过单个控制点协调所有属性更改。

#5


1  

Here is a case when it's better to use move :

这里有一个最好使用move的例子:

If you are overriding the updateDisplayList() method in a custom component, you should call the move() method rather than setting the x and y properties.The difference is that the move() method changes the location of the component and then dispatches a move event when you call the method, while setting the x and y properties changes the location of the component and dispatches the event on the next screen refresh.

如果在自定义组件中重写updateDisplayList()方法,则应该调用move()方法,而不是设置x和y属性。不同之处在于,move()方法更改组件的位置,然后在调用该方法时分派一个move事件,同时设置x和y属性更改组件的位置,并在下一次屏幕刷新时分派事件。

#6


0  

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

Always look here to know exactly. If you mean UIControl, then look at [PATH_ABOVE]\mx\core\UIObject.as

总是在这里看清楚。如果您是指UIControl,那么请查看[PATH_ABOVE]\mx core\UIObject.as

And you'll 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 a 'move' event, supplied by old coordinates. That's all.

因此,正确的答案是:在分配新的坐标之后,该方法分派一个由旧坐标提供的“move”事件。这是所有。

PS: if you use another flash compiler - just find it's class definitions somewhere on your machine...

PS:如果你使用另一个flash编译器,只要在你的机器上找到它的类定义。

#1


2  

What is a? If we knew what 'a' is then it would make it simpler to answer. The a.x or a.y would normaly specify the coordinates for the top left hand corner of the object (say Button) in its parent (say Canvas).

一个是什么?如果我们知道a是什么,那么答案就会更简单。一个。x或。y将在其父(比如画布)中指定对象左上角的坐标(比如按钮)。

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

如果“a”是一个按钮,那么设置.x和.y或设置move(x, y)也会起到同样的作用。

Check the docs out 'Moves the component to a specified position within its parent. Calling this method is exactly the same as setting the component's x and y properties. '

检查文档是否将组件移动到父组件的指定位置。调用此方法与设置组件的x和y属性完全相同。”

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

这在http://livedocs.adobe.com/flex/3/langref/index.html的UIComponent之下。

#2


2  

In general: calling a method communicates what you're doing, just poking member variables doesn't.

一般来说:调用一个方法会传递您正在做的事情,而只是戳成员变量则不会。

As ChrisF said, there might also be a difference where poking moves to absolute coordinates, while the method call moves relative to the current position. I tried looking up a reference, but didn't find one.

正如ChrisF所说,在将移动到绝对坐标时,也可能有不同,而方法调用相对于当前位置的移动。我试着找一份推荐信,但没有找到。

#3


1  

Just guessing (I don't know actionscript) but I would have thought that

只是猜测(我不知道actionscript)但是我想过

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

would set a to be (100, 100), while

将a设为(100,100

a.move(100,100);

would add (100,100) to the current value of a. However, in light of the accepted answer it appears it does the same. Though the following advice still holds:

将(100,100)加到a的当前值,但是,根据所接受的答案,它似乎是一样的。尽管以下建议仍然有效:

Have you tried the latter for different initial values of a (0, 0), (100, 100), (23, 42) etc. and checked what happens?

对于a(0,0)、(100,100)、(23,42)等不同的初始值,你是否尝试过后一种方法?

If you're not sure about something test it out - you're not going break anything and it even getting it wrong first time can teach you something.

如果你对某件事不确定,那就试一试——你不会打破任何东西,即使第一次出错也能教会你一些东西。

I did a quick search for some documentation, but wasn't able to turn anything up. I think your best bet is to generate some test examples to explore what each approach does.

我快速搜索了一些文档,但是什么都找不到。我认为您最好的方法是生成一些测试示例来探究每种方法的作用。

#4


1  

ActionScript properties can in fact, be backed by methods - so called getter/setter pairs. So when you set the property a.x = 100, there's quite likely code that is executing to deal with the implications of that property change. (Not knowing what type a is here, it's not possible to know for sure - indeed, it's never possible to know in general, and you shouldn't assume that you do)

ActionScript属性实际上可以由方法支持——所谓的getter/setter对。当你设置属性a。x = 100,有很可能的代码正在执行以处理该属性变化的影响。(不知道a在这里是什么,这是不可能确定的——事实上,通常不可能知道,而且你不应该假设你是这样做的)

Be careful about one thing here: calling a single method such as a.move(x,y) could be quite different from calling two the two separate setter methods behind a.x = q and a.y = r It all depends on how the class you're using has been implemented. For this reason, many Flex framework classes (all?) use the invalidateProperties() ... commitProperties() pattern to ensure that all property changes are coordinated through a single control point.

这里要注意一件事:调用单个方法(如a.move(x,y))可能与调用两个位于a后面的独立setter方法非常不同。x = q和a。这完全取决于您使用的类是如何实现的。由于这个原因,许多Flex框架类(全部?)都使用invalidateProperties()……commitProperties()模式,以确保通过单个控制点协调所有属性更改。

#5


1  

Here is a case when it's better to use move :

这里有一个最好使用move的例子:

If you are overriding the updateDisplayList() method in a custom component, you should call the move() method rather than setting the x and y properties.The difference is that the move() method changes the location of the component and then dispatches a move event when you call the method, while setting the x and y properties changes the location of the component and dispatches the event on the next screen refresh.

如果在自定义组件中重写updateDisplayList()方法,则应该调用move()方法,而不是设置x和y属性。不同之处在于,move()方法更改组件的位置,然后在调用该方法时分派一个move事件,同时设置x和y属性更改组件的位置,并在下一次屏幕刷新时分派事件。

#6


0  

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

Always look here to know exactly. If you mean UIControl, then look at [PATH_ABOVE]\mx\core\UIObject.as

总是在这里看清楚。如果您是指UIControl,那么请查看[PATH_ABOVE]\mx core\UIObject.as

And you'll 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 a 'move' event, supplied by old coordinates. That's all.

因此,正确的答案是:在分配新的坐标之后,该方法分派一个由旧坐标提供的“move”事件。这是所有。

PS: if you use another flash compiler - just find it's class definitions somewhere on your machine...

PS:如果你使用另一个flash编译器,只要在你的机器上找到它的类定义。