PDA

View Full Version : C++ Style Pointers?


ScottH87
11-26-2009, 03:10 PM
Hi,

I'm fairly new to actionscript but not new to programming. I've had around for years of using C/C++ as a student before now.

Basically my question is, does AS3 have any functionality comparible to pointers in C/C++?

I'm trying to implement the A* algorithm into my Flex project, but am finding it difficult due to getting used too pointers when coding in C++. When I used A* in C++ I found pointers to be almost essential with the amount of data getting stored and passed around. Now I can even get the algorithm to work right :S

Please help

Thanks

maskedMan
11-26-2009, 04:17 PM
Actionscript does not support C/C++ style pointers that I'm aware of, unless you're using Alchemy.

Of course, if you're using Alchemy, you're writing in C/C++ anyway, and not Actionscript.

lordofduct
11-26-2009, 06:32 PM
as maskedman says, no pointers in AS3. Two completely different kinds of languages.

Anways though... here is an A* algorithm I wrote in AS3:

http://code.google.com/p/lodgamebox/source/browse/trunk/com/lordofduct/engines/ai/AStarMonotonic.as

the differenty types usable with it are in the package:

http://code.google.com/p/lodgamebox/source/browse/#svn/trunk/com/lordofduct/engines/ai

ScottH87
11-26-2009, 08:19 PM
Ok so can i ask how i would go about implementing the following scenario.

I have a Class "X" and a class "Y" both seperate from each other. However at one point in some methods inside "X" i need the information held in "Y". Now we're talking about alot of data here not just a couple of ints that are needed, the whole class will be needed to either get, set or use variables.

In C++ i'd pass in a pointer to "Y" into "X" either in the constructor or another method. This means i'm only passing about a small memory address rather than a whole classes worth of data. How would I best go about this in AS3.0?

bowljoman
11-26-2009, 09:00 PM
think of all vars as pointers, and simply pass one class to anothers method, and parameter typed as the class.

Then you can read the vars and use methods as needed.


a:ClassA=new ClassA();

b:ClassB=new ClassB();

b.setClassAReference(a);

bowljoman
11-26-2009, 09:05 PM
if classB has a var ref:ClassA;It will only be a pointer to the same data structure in memory, unless you call 'new' and copy it to a new instance.

Only the memory address of the OBjectA will be held in the other's class member.

abeall
11-26-2009, 10:16 PM
as maskedman says, no pointers in AS3. Two completely different kinds of languages.

Anways though... here is an A* algorithm I wrote in AS3:

http://code.google.com/p/lodgamebox/source/browse/trunk/com/lordofduct/engines/ai/AStarMonotonic.as

the differenty types usable with it are in the package:

http://code.google.com/p/lodgamebox/source/browse/#svn/trunk/com/lordofduct/engines/ai

This looks really cool, do you have any documentation, or plans add asdoc comments? I don't have immediate use but I've been looking for a good non-tile-based pathfinding algorithm I can integrate with my own code for a long time...