I'm trying to port some code from AcrionScript3. The code uses the "New" operator. I believe it is similar to "New" in VB6. Any ideas on how to achieve the same thing with B4A?
Below is part of the code I am porting. The function cloneVector is suppose to clone the very object that is associated with the class that this function is in.
B4X:
public class Vector2D {
private var _x:Number;
private var _y:Number;
/**
* Constructor
*/
public function Vector2D(x:Number = 0, y:Number = 0) {
_x = x;
_y = y;
}
/**
* Creates an exact copy of this Vector2D
* @return Vector2D A copy of this Vector2D
*/
public function cloneVector():Vector2D {
return new Vector2D(x, y);
}
I think you would just dim a new variable of the vector class, initialize it and return it. something like:
B4X:
'this is somewhere in your project
dim ClonedVector2D as Vector2D 'this will be your clone
ClonedVector2D=IWantToCloneVector2D.cloneVector
'this is in your Vector2D class
public sub cloneVector as Vector2D
dim NewVector2D as Vector2D
NewVector2D.Initialize(me.x,me.y) 'probably don't need "me"
return NewVector2D
end sub