# Actionscript to retrieve data from database

**URL:** https://forum.kirupa.com/t/actionscript-to-retrieve-data-from-database/193417
**Category:** flash
**Created:** [July 13, 2006, 6:12am UTC](https://forum.kirupa.com/t/actionscript-to-retrieve-data-from-database/193417 "2006-07-13T06:12:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![santalea](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@santalea](https://forum.kirupa.com/u/santalea)
#### Post date: [July 13, 2006, 6:12am UTC](https://forum.kirupa.com/t/actionscript-to-retrieve-data-from-database/193417/1 "2006-07-13T06:12:51Z")

</div>

i have to create an actionscript to retrieve data from the database. i have a database(mySQL) called mapping with the fields Longitude, Latitude and Angle.  
this is my jsp file:

```auto
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ include file="mysqlConfig.jsp" %>
 
<%
Connection connection = null;
String str="";
 
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(s1_db, db_user, db_pw);
Statement statement = connection.createStatement();
 
ResultSet rs = statement.executeQuery("SELECT * FROM mapping");
//String[][] data = new String[11][10];
 
int x = 0;
while (rs.next()) {
//noinspection UnusedAssignment
str = str + "&Longitude" + x + "=" + rs.getString("Longitude") + "&Latitude" + x + "=" + rs.getString("Latitude") +
"&Angle" + x + "=" + rs.getString("Angle") + "&" + "<br>";
 
x++;
}
 
out.println(str);
 
} catch(ClassNotFoundException cnfe){
System.out.println("Database driver not found:" + cnfe.getMessage());
} catch(SQLException sqlexception){
System.out.println("Error opening the db connection: " + sqlexception.getMessage());
} finally {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
%>

```

from this jsp file, i have to use the function LoadVars to receive the data that is retrieve by this file from my database. i started the actionscript as show below but i need to incoporate it with the other actionscript. as in i have to use the longitude and latitude as the multidimensional array.

this is the one that is connected with the jsp

[AS]

[FONT=Courier New][LEFT][FONT=Verdana]#include “tomcatURL.as”[/FONT]  
[FONT=Verdana]var mUnit:Array = new Array();[/FONT]  
[FONT=Verdana]//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
// function to connect database for initial positions of active objects in Battlescape  
// also to insert new entries to all logs  
function initMap():Void {  
var send\_lv:LoadVars = new LoadVars();  
var rec\_lv:LoadVars = new LoadVars();

// Battlescape to receive data from test.mapping using main.jsp  
send\_lv.sendAndLoad(\_global.serverURL + “mine.jsp”, rec\_lv, “POST”);  
rec\_lv.onLoad = function(success:Boolean) {  
if (success) {  
var i:Number = 0;  
while (rec\_lv[“Longitude”+i] != null){  
mUnit\* = new Mappie(rec\_lv[“Longitude”+i], rec\_lv[“Latitude”+i], rec\_lv[“Angle”+i]);  
i++;

}[/FONT]  
[FONT=Verdana] }  
}  
}  
[/AS][/FONT][/LEFT]

[/FONT]

this is the one that needs to be modify so that it would be connected to the jsp (help me on this one plz)

[AS]

[FONT=Courier New][LEFT][FONT=Verdana]var targetIndex:Number = 0;  
//var xValues:Array = [100,200,220,300,330,370];  
//var yValues:Array = [100,150,220,300,310,400];  
var tarArray:Array = [[70,120], [80,215], [110,270], [170,320], [225,280], [300,360], [355,430], [520,380], [610,500]];  
this.createEmptyMovieClip(“line\_mc”, 1); //creating the line  
this.attachMovie(“arrowmc”, “arrowmc”, this.getNextHighestDepth()); //inserting the mc  
line\_mc.lineStyle(2, 0xFF00FF, 30);  
line\_mc.moveTo(tarArray[0][0], tarArray[0][1]); // starting point of the target  
arrowmc.\_x = tarArray[0][0];  
arrowmc.\_y = tarArray[0][1]; [/FONT]  
[FONT=Verdana]var move\_int = setInterval(moveChaser,50); //setting time delay between movements[/FONT]  
[FONT=Verdana]function moveChaser() {  
//works out the angle in radians between tarArray[targetIndex] and arrowmc  
var theta:Number = Math.atan2(tarArray[targetIndex][1] - arrowmc.\_y, tarArray[targetIndex][0] - arrowmc.\_x);  
//changes radians to degrees and orientates it 90 more degrees because in flash 0 degrees is facing right  
arrowmc.\_rotation = (theta \* 180 / Math.PI)+90;

//checks that tarArray[targetIndex] and arrowmc are more than 2 away from each other  
if(Math.abs((tarArray[targetIndex][0]-arrowmc.\_x)) \> 2 || Math.abs((tarArray[targetIndex][1]-arrowmc.\_y)) \> 2){  
//moves arrowmc 3 towards tarArray[targetIndex]  
arrowmc.\_x += Math.cos(theta) \* 3;  
arrowmc.\_y += Math.sin(theta) \* 3;  
//draws the line to wherever arrowmc is  
line\_mc.lineTo(arrowmc.\_x , arrowmc.\_y);  
}

route\_btn.onRelease = function(){  
//test for no more targets in tarArray  
if(tarArray[targetIndex][0] == undefined){  
clearInterval(move\_int);  
trace(“successful”);  
}  
//to go to the next Array  
targetIndex++;  
trace(“Target Index:” +targetIndex)  
}  
};[/FONT]  
[FONT=Verdana][/AS][/FONT][/LEFT]  
[/FONT]
