Results 1 to 7 of 7
Thread: Migrate AS3 to Java
- 07-02-2011, 09:39 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 3
- Rep Power
- 0
Migrate AS3 to Java
Hi Forum,
im quite new to Java, but i've been programming AS3 for quite a while now and it's time to dig more into java. So i'll be around more often in future.gif)
Not much difference, i know, but i'm haveing problems with the datatypes.
I made a flash game that expects an Array of Integers, which atm i am generating inside flash, for various reasons these need to come from the server. Ive got a java servlet and sending the array is not the problem, but when i try to convert my number generator from as3 to java i cant get seem to get the right datatypes.
this is my generator in as3.
var randomNumbers = new Array;Java Code:function generateRandomNumbers() { var randomNumbers = new Array; var lastRanNum:uint; var ranNumber:uint; var superProbability = 0.5; var jokerProbability = 0.2; var superJokerProbability = 0.2; var ranSuperNumber:uint; var fieldLength:uint = 85; for (var i:uint=0; i<(fieldLength); i++) { var ranSuper = Math.random(); var ranJoker = Math.random(); var ranSuperJoker = Math.random(); if (ranSuper > superProbability) { if (ranJoker < jokerProbability) { randomNumbers.push(0); } else { ranNumber = Math.floor(Math.random() * 9) + 1; while (ranNumber == lastRanNum || ranNumber == lastRanNum + 10) { ranNumber = Math.floor(Math.random() * 9) + 1; } lastRanNum = ranNumber; randomNumbers.push(ranNumber); } } else { if (ranSuperJoker < superJokerProbability) { randomNumbers.push(10); } else { ranSuperNumber = Math.floor(Math.random() * 9) + 10; while (ranSuperNumber == lastRanNum || ranSuperNumber == lastRanNum - 10) { ranSuperNumber = Math.floor(Math.random() * 9) + 10; } lastRanNum = ranSuperNumber; randomNumbers.push(ranSuperNumber); } } } //MonsterDebugger.trace(this,randomNumbers); }
in as3 need to become
randomList = new ArrayList<Integer>();
How would i write this in java? Help would be somuch appreciated
, i'm sure it will help me understanding the datatype situation alot better.
THX
ps:i can help out in any as3/flash related issues for the future
- 07-02-2011, 09:47 PM #2
How would i write this in java?Java Code:ArrayList<Integer> randomList = new ArrayList<Integer>();
- 07-02-2011, 09:48 PM #3
@Fubarable: I think he means Java; he refers to a servlet, ArrayList, and Integer types (none of which are present in JavaScript).
-
Thanks Zack. Deleting my erroneous earlier post.
- 07-02-2011, 10:02 PM #5
Member
- Join Date
- Jul 2011
- Posts
- 3
- Rep Power
- 0
Yes i mean Java! i'm fetching vars from a DB with java persistence, and additionally i want to create that array and send it to flash along with the rest.
i'm haveing troubles with this for example
java semms to expect ranNumber to be a Double, but to add it to the ArrayList it needs to be an intJava Code:ranNumber = Math.floor(Math.random() * 9) + 1;
whe i try
it cant resolve methodJava Code:ranNumber.intValue()
Last edited by M4tchB0X3r; 07-02-2011 at 10:04 PM. Reason: typo's XD
- 07-02-2011, 10:12 PM #6
Java is case sensitive. Double is a class and double is a primitive.
The Math.floor() method returns a double. You can cast it to an int by adding (int) before the Math....
Another item. You can only add objects to an ArrayList. So you would be adding Integer class objects.to add it to the ArrayList it needs to be an int
The compiler with automatically convert (autobox) an int to an Integer if you use the add() method.
- 07-02-2011, 11:09 PM #7
Member
- Join Date
- Jul 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Migrate from PHP to J2EE
By venky in forum Advanced JavaReplies: 0Last Post: 06-01-2010, 09:24 PM -
migrate JSP website
By valhensing in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 12-14-2009, 03:34 PM -
This project needs to migrate WPT metadata
By Arthur Gardner in forum EclipseReplies: 5Last Post: 12-11-2009, 10:49 PM -
migrate to Netbeans
By Jack in forum NetBeansReplies: 3Last Post: 07-02-2007, 01:26 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks