Error: Expecting rightparen before colon - actionscript-3

I'm working on an actionscript and I can'f seem to find the problem on this code block.
Please help.
Partial code:
private function constructCommunicatorAndConnect() : void
{
var cHost:* = ExternalData.splashServerHosts[this.m_nSplashServerIndex];
var nPort:* = int(ExternalData.splashServerPorts[this.m_nSplashServerIndex]);
var cSocket:* = new ReconnectingStringSocket(cHost, nPort, new RandomXORScrambler(68, 47));
cSocket.addEventListener(ReconnectingStringSocket.RECONNECTING, function (event:Event) : void
{
MultiplayerContainer.addTextToConsole("Lost splash connection, trying to reconnect...");
return;
}// end function
);
cSocket.addEventListener(ReconnectingStringSocket.RECONNECTING_SUCCESSFUL, function (event:Event) : void
{
MultiplayerContainer.addTextToConsole("Splash connection succesfully reestablished");
return;
}// end function
);
this.m_cSplashCommunicator = new SplashCommunicator(cSocket, MultiplayerContainer.player.com.miniclip.multiplayer.container.player:ILocalPlayer::sessionID, MultiplayerContainer.player.userID, ExternalData.gameID, this);
this.m_cSplashCommunicator.connect();
MultiplayerContainer.addTextToConsole("Connecting to splash server #" + this.m_nSplashServerIndex + " (" + cHost + ":" + nPort + ") with session \"" + MultiplayerContainer.player.sessionID + "\"");
dispatchEvent(new Event(COMMUNICATOR_CONSTRUCTED));
return;
}// end function
The error is at
this.m_cSplashCommunicator = new SplashCommunicator(cSocket, MultiplayerContainer.player.com.miniclip.multiplayer.container.player:ILocalPlayer::sessionID, MultiplayerContainer.player.userID, ExternalData.gameID, this);
Some relevant functions:
public function SplashCommunicator(param1:StringSocket_i, param2:String, param3:String, param4:String, param5:ISplashListener)
{
super(param1, param5);
param1.setSocketEventHandler(this.handleSocketEvent);
param1.addEventListener(Event.CONNECT, this.socketConnected);
this.m_cSessionID = param2 != null ? (param2) : ("");
this.m_cUserID = param3 != null ? (param3) : ("");
this.m_cGameID = param4;
this.m_cListener = param5;
return;
}// end function

heres your problem, Check your code
.player:ILocalPlayer::sessionID, Multiplaye // check these ::
whatever = new whatever(somemorestuff,hi{in here is where you have ::::::::::},outside);
See the above pattern the colon is inside the parentheses (MC{x:200,y:200});
Im hoping your following me

Related

as3 why is my public var changing?

I have a var called "currentMystery" I have reduced the issue down to these two functions
I believe. Anyway, the first time through it works and traces a var from an Array... but the second time through something is changing it to [Event type="soundComplete" bubbles=false cancelable=false eventPhase=2]
What in the code is changing this or what am I doing wrong?
Thanks so much!
Any ideas on how to keep it as the same var as it assigned here:
currentMystery = "" + Mystries[4] + "";
...
public static var Mystries:Array = new Array("null","Joyful","Luminous","Sorrowful","Glorious");
public function checkDecade(e:Event = null)
{
if (decadeCount < 6)
{
Announce = true;
currentMystery = "" + Mystries[4] + "";
prayDecade(currentMystery);
}
}
public function prayDecade(currentMystery:String)
{
//// MY ISSUE IS WITH currentMystery. First time through
//// it works but the second through it is changing to
//// something like [Event type="soundComplete" bubbles=false etc...
trace("Pray Decade called: " +currentMystery);
if (Announce)
{
/// Sets PAUSE before Announc || Add features later to all prayers
setTimeout(function()
{
MainDoc.cPrayer.text = currentMystery;
trace("Called Announce"+decadeCount);
trace("Called Announce: Mystery: " + currentMystery+" Current Decade: " +decadeCount);
theAnnounce = new Sound();
theAnnounce.load(new URLRequest("audio/Rosary/Announce/"+currentMystery+"/"+decadeCount+".mp3"));
Praying = theAnnounce.play();
Praying.addEventListener(Event.SOUND_COMPLETE, prayDecade );
Announce = false;
}, 2000);
}
else
{
if (prayerCount==0)
{
trace("Our Father " + decadeCount);
//trace(love);
Begin = true;
/// Sets PAUSE before Our Father || Add features later to all prayers
setTimeout(function()
{
Begin = true;
ourFather();
}, 2000);
}
if (prayerCount >0 && prayerCount<11)
{
trace("Hail Mary " + prayerCount);
Begin = true;
hailMary();
}
if (prayerCount==11)
{
trace("Glory Be... " + prayerCount);
Begin = true;
gloryBe();
}
if (prayerCount==12)
{
trace("Oh My Jesus... " + prayerCount);
Begin = true;
ohMyJesus();
}
function ourFather(e:Event = null)
{
if (Begin)
{
Praying = OFB.play();
Praying.addEventListener(Event.SOUND_COMPLETE, ourFather );
}
else
{
Praying = OFE.play();
Praying.addEventListener(Event.SOUND_COMPLETE, prayDecade );
prayerCount++;
}
Begin = false;
}
function hailMary(e:Event = null)
{
if (Begin)
{
Praying = HMB.play();
Praying.addEventListener(Event.SOUND_COMPLETE, hailMary );
}
else
{
Praying = HME.play();
Praying.addEventListener(Event.SOUND_COMPLETE, prayDecade );
prayerCount++;
}
Begin = false;
}
function gloryBe(e:Event = null)
{
if (Begin)
{
Praying = GBB.play();
Praying.addEventListener(Event.SOUND_COMPLETE, gloryBe );
}
else
{
Praying = GBE.play();
Praying.addEventListener(Event.SOUND_COMPLETE, checkDecade );
prayerCount++;
}
Begin = false;
}
function ohMyJesus(e:Event = null)
{
Praying = OMJ.play();
Praying.addEventListener(Event.SOUND_COMPLETE, checkDecade );
prayerCount = 0;
decadeCount++;
}
}//End if Else
}
You're using the prayDecade method as a handler for the sound complete event as well as calling it directly in your code. When it is invoked as an event handler, the parameter it receives is an event object which is being cast to a string and overwriting your public variable within the local (prayDecade function) scope.
I think if you update the function as follows you'll get the results you expect (assuming currentMystery is a public variable in the class scope:
public function prayDecade(e:Event)
{
trace("Pray Decade called: " + currentMystery);
// ....
}
And when you invoke the method directly, don't pass the variable:
// Assuming currentDecade is in scope in the prayDecade method
prayDecade(/*currentMystery*/);
What in the code is changing this or what am I doing wrong?
Event handler for the 'SoundChannel' is wrong.
Praying.addEventListener(Event.SOUND_COMPLETE, prayDecade );
In the prayDecade as an argument will be passed event object (Event.SOUND_COMPLETE), not a string as you are waiting for. So [Event type="soundComplete" bubbles=false cancelable=false eventPhase=2] is a String representation of event.

Cannot implicitly convert type 'System.Data.DataSet' to 'System.Collections.Generic.List<CalendarEvent>''

I am new to application block.
I am trying to get data from database. Following is the code snap.
JsonResponse.ashx:
public void ProcessRequest(HttpContext context)
{
HttpContext _context = HttpContext.Current;
context.Response.ContentType = "application/json";
int user_id = Convert.ToInt32(HttpContext.Current.Session["userid"]);
DateTime start = new DateTime(1970, 1, 1);
DateTime end = new DateTime(1970, 1, 1);
start = start.AddSeconds(double.Parse(context.Request.QueryString["start"]));
end = end.AddSeconds(double.Parse(context.Request.QueryString["end"]));
String result = String.Empty;
result += "[";
List<int> idList = new List<int>();
foreach (CalendarEvent cevent in EventDAO.getEvents(start, end, user_id))
{
result += convertCalendarEventIntoString(cevent);
idList.Add(cevent.id);
}
if (result.EndsWith(","))
{
result = result.Substring(0, result.Length - 1);
}
result += "]";
//store list of event ids in Session, so that it can be accessed in web methods
context.Session["idList"] = idList;
context.Response.Write(result);
}
private String convertCalendarEventIntoString(CalendarEvent cevent)
{
String allDay = "true";
if (ConvertToTimestamp(cevent.start).ToString().Equals(ConvertToTimestamp(cevent.end).ToString()))
{
if (cevent.start.Hour == 0 && cevent.start.Minute == 0 && cevent.start.Second == 0)
{
allDay = "true";
}
else
{
allDay = "false";
}
}
else
{
if (cevent.start.Hour == 0 && cevent.start.Minute == 0 && cevent.start.Second == 0
&& cevent.end.Hour == 0 && cevent.end.Minute == 0 && cevent.end.Second == 0)
{
allDay = "true";
}
else
{
allDay = "false";
}
}
return "{" +
"id: '" + cevent.id + "'," +
"title: '" + HttpContext.Current.Server.HtmlEncode(cevent.title) + "'," +
"start: " + ConvertToTimestamp(cevent.start).ToString() + "," +
"end: " + ConvertToTimestamp(cevent.end).ToString() + "," +
"allDay:" + allDay + "," +
"user_id:" + cevent.user_id + "," +
"description: '" + HttpContext.Current.Server.HtmlEncode(cevent.description) + "'" +
"},";
}
DA:
public static List<CalendarEvent> getEvents(DateTime start, DateTime end, int user_id)
{
List<CalendarEvent> events = new List<CalendarEvent>();
SqlParameter[] sqlParam = new SqlParameter[3];
sqlParam[0] = new SqlParameter("#start", start);
sqlParam[1] = new SqlParameter("#end", end);
sqlParam[2] = new SqlParameter("#user_id", user_id);
return SqlHelper.ExecuteDataset(connectionString,CommandType.StoredProcedure, "GetData", sqlParam);
}
sqlhelper:
public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = 120;
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);
//create the DataAdapter & DataSet
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
//fill the DataSet using default values for DataTable names, etc.
da.Fill(ds);
// detach the SqlParameters from the command object, so they can be used again.
cmd.Parameters.Clear();
//return the dataset
return ds;
}
I am getting error:
Cannot implicitly convert type 'System.Data.DataSet' to 'System.Collections.Generic.List'.
I am unable to understand what is the problem.
In getEvents method, you need to iterate through the records in the dataset and fill in the list that you would return in this method.
var dataset = SqlHelper.ExecuteDataset(connectionString,CommandType.StoredProcedure, "GetData", sqlParam);
foreach (var row in ds.Tables["FooTable"].Rows)
{
events.Add(new CalendarEvent(...));
}
return events;
That's because you try to return a dataset as List, which it isn't.
You need to convert the dataset to a list. A possible solution would be to change the getEvents method to something like this ->
public static List<CalendarEvent> getEvents(DateTime start, DateTime end, int user_id)
{
List<CalendarEvent> events = new List<CalendarEvent>();
SqlParameter[] sqlParam = new SqlParameter[3];
sqlParam[0] = new SqlParameter("#start", start);
sqlParam[1] = new SqlParameter("#end", end);
sqlParam[2] = new SqlParameter("#user_id", user_id);
var ds = SqlHelper.ExecuteDataset(connectionString,CommandType.StoredProcedure, "GetData", sqlParam);
return ds.Tables[0].AsEnumerable().Select(datarow => new CalendarEvent{ Title = datarow.Field<string>("Title), /*the rest of your params*/}).ToList();
}
Your problem is this piece of code:
public static List<CalendarEvent> getEvents(DateTime start, DateTime end, int user_id)
{
List<CalendarEvent> events = new List<CalendarEvent>();
SqlParameter[] sqlParam = new SqlParameter[3];
sqlParam[0] = new SqlParameter("#start", start);
sqlParam[1] = new SqlParameter("#end", end);
sqlParam[2] = new SqlParameter("#user_id", user_id);
return SqlHelper.ExecuteDataset(connectionString,CommandType.StoredProcedure, "GetData", sqlParam);
}
You defined the type of this method as List<CalenderEvent> but you return a DataSet.
I do not know which datatables are contained in your dataset, but I assume there is one which represents your calenderevents.
This means you need to extract the data you want from your dataset and make a list out of it. Assuming there is one table in your dataset your new method would look something like this:
public static List<CalendarEvent> getEvents(DateTime start, DateTime end, int user_id)
{
List<CalendarEvent> events = new List<CalendarEvent>();
SqlParameter[] sqlParam = new SqlParameter[3];
sqlParam[0] = new SqlParameter("#start", start);
sqlParam[1] = new SqlParameter("#end", end);
sqlParam[2] = new SqlParameter("#user_id", user_id);
var data = SqlHelper.ExecuteDataset(connectionString,CommandType.StoredProcedure, "GetData", sqlParam);
events = ds.Tables[0].AsEnumerable().Select(r => new CalenderEvent
{
//using dummy properties because I dont know
//your class
Property1 = r.Field<string>("Column1"),
Property2 = r.Field<string>("column2"),
//...
}).ToList();
return events;
}

How to append results in Processing?

I have implemented the Table() function in order to save the results generated by the application. However, it seems that the Timer function in the application causes the application to write over the existing CSV file each time it runs. Rather than write over the existing CSV file, I would like to append the newest search results to the existing CSV file. Is there a way to do this? Is it easier to append the results if the results are stored in a different format such as JSON?
Timer timer;
import java.util.List;
Table table;
long lastID = Long.MAX_VALUE;
void setup() {
timer = new Timer(30000);
timer.start();
goTwitter();
table = new Table();
table.addColumn("id");
table.addColumn("latitude");
table.addColumn("longitude");
}
void draw(){
if (timer.isFinished()){
goTwitter();
timer.start();
}
}
void goTwitter(){
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("");
cb.setOAuthConsumerSecret("");
cb.setOAuthAccessToken("");
cb.setOAuthAccessTokenSecret("");
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Query query = new Query("#love");
int numberOfTweets = 300;
ArrayList<Status> tweets = new ArrayList<Status>();
while (tweets.size () < numberOfTweets) {
if (numberOfTweets - tweets.size() > 100)
query.setCount(100);
else
query.setCount(numberOfTweets - tweets.size());
//long lastID = Long.MAX_VALUE;
try {
QueryResult result = twitter.search(query);
tweets.addAll(result.getTweets());
println("Gathered " + tweets.size() + " tweets");
for (Status t: tweets)
if(t.getId() < lastID) lastID = t.getId();
}
catch (TwitterException te) {
println("Couldn't connect: " + te);
};
query.setSinceId(lastID);
}
for (int i = 0; i < tweets.size(); i++) {
Status t = (Status) tweets.get(i);
GeoLocation loc = t.getGeoLocation();
String user = t.getUser().getScreenName();
String msg = t.getText();
String time = "";
if (loc!=null) {
Double lat = t.getGeoLocation().getLatitude();
Double lon = t.getGeoLocation().getLongitude();
println(i + " USER: " + user + " wrote: " + msg + " located at " + lat + ", " + lon);
TableRow newRow = table.addRow();
newRow.setString("id", user);
newRow.setDouble("latitude", lat);
newRow.setDouble("longitude", lon);
saveTable(table, "data2/syria_16500_5.csv");
}
}
println("lastID= " + lastID);
}
class Timer {
int savedTime;
int totalTime;
Timer (int tempTotalTime) {
totalTime = tempTotalTime;
}
void start(){
savedTime = millis();
}
boolean isFinished() {
int passedTime = millis() - savedTime;
if (passedTime > totalTime){
return true;
} else {
return false;
}
}
}
Well, there does not seem to be a direct implementation to append to a table, so you'll have to resort to a hack: load the table in processing, write to it and resave it, sort of like this:
processing.data.Table table;
void setup() {
File f = new File(sketchPath("") + "data2/syria_16500_5.csv");
println(f.getAbsolutePath());
if (!f.exists()) {
table = new processing.data.Table();
table.addColumn("id");
table.addColumn("latitude");
table.addColumn("longitude");
}
else
table = loadTable("data2/syria_16500_5.csv", "header, csv");
TableRow newRow = table.addRow();
newRow.setString("id", "asad");
newRow.setDouble("latitude", 234);
newRow.setDouble("longitude", 2523);
saveTable(table, "data2/syria_16500_5.csv");
}
The sketch first checks if the file exists. If it does not, it creates a new table, otherwise it loads the old table in with its header.
Be warned, this is not particularly safe... If you change your columns (say, in a text editor) and try to run the sketch again you will get an exception.

Pass actual variable object to a function

The problem is simple:
I need to pass actual variable to a function.
private var test:String = "KKK";
trace (" Before --->>> " + test);
testFunction(test);
trace (" Next --->>> " + test);
private function testFunction(d:String):void{
d = "MMM";
}
Result:
Before --->>> KKK
Next --->>> KKK
The result is correct but, What I want is, send the actual test variable to my function and change that. So I want to have output like this:
Before --->>> KKK
Next --->>> MMM
Any solution?
Thanks for your answer but if I have a code like this, I need to pass the actual variable to my function:
if ( lastPos == -1 ){// if this is first item
flagLEFT = "mid";
tempImageLEFT = new Bitmap(Bitmap(dataBANK[0]["lineimage" + 10]).bitmapData);
}else if (nextPos == -1){// if this is the last position
flagRIGHT = "mid";
tempImageRGHT = new Bitmap(Bitmap(dataBANK[0]["lineimage" + 13]).bitmapData);
}
As you see, changes are in flagLEFT and tempImageRGHT . Also I have a change on numbers (10 and 13) which can be handle in normal way. I need something like this:
private function itemFirstLast(flag:String, bmp:Bitmap, pos:int):void{
flag = "mid";
bmp = new Bitmap(Bitmap(dataBANK[0]["lineimage" + pos]).bitmapData);
}
Any solution?
One way is to return the new string and assign it to test :
private var test:String = "KKK";
trace (" Before --->>> " + test);
test = testFunction(test);
trace (" Next --->>> " + test);
private function testFunction(d:String):String{
d = "MMM";
return d;
}
This still doesn't pass the actual string object but the test string will change. Strings are passed by value in AS3, if you wan't to actually pass it in you can wrap it in an object :
var object:Object {
"test":"KKK"
};
trace (" Before --->>> " + object["test"]);
testFunction(object);
trace (" Next --->>> " + object["test"]);
private function testFunction(o:Object):void{
o["test"] = "MMM";
}
You'll need to wrap it in a class instance:
class StringValue{
function StringValue( value : String ) : void{
this.value = value;
}
public var value : String;
public function toString() : String{
return value;
}
}
private var test:StringValue = new StringValue( "KKK" );
trace (" Before --->>> " + test);//traces 'KKK'
testFunction(test);
trace (" Next --->>> " + test);//traces 'MMM'
private function testFunction(d:StringValue):void{
d.value = "MMM";
}
Please refer to the following link:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f56.html
You need to wrap it in the Object .

Sending Json Form from Flash AS3

i am having one form accepting json post in Asp.net which i need to call from Flash As3...
i am using below code to do that. I have seen some post in which they say its working fine.
But i am encountering below Error
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
Here is my code.
var messages:Array = new Array ();
messages.push({"From":fromemailTxt.text,"To": ToemailTxt.text,"Body": BodyText.text,"Subject":SubjectText.text});
var JsonObj:String = JSON.encode(messages);
trace(JsonObj);
var variables:URLVariables=new URLVariables(JsonObj);
RequestURL= srvStringURL;
var JSONLoader:URLLoader = new URLLoader();
JSONLoader.dataFormat=URLLoaderDataFormat.TEXT;
JSONLoader.addEventListener(IOErrorEvent.IO_ERROR, GetBookmarkURLError, false, 0, true);
JSONLoader.addEventListener(Event.COMPLETE, parseBookmarkURLResult, false, 0, true);
var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json");
var request:URLRequest = new URLRequest(RequestURL);
request.requestHeaders.push(hdr);
request.data=variables;
request.method = URLRequestMethod.POST;
try
{
JSONLoader.load(request);
}
catch (error:ArgumentError)
{
trace("An ArgumentError has occurred."+error.errorID.toString());
}
catch (error:SecurityError)
{
trace("A SecurityError has occurred.");
}
catch (error:Error)
{
trace("Unable to load requested document.");
}
Anybody have any idea on this??
Thanks
The error is, because you are passing incorrect string to URLVariables constructor. Do not use URLVariables. Instead pass data as string: request.data=JsonObj;
Below is the code I am using to consume REST Web service and pass json parameter to service it shows. Error #2032: Stream Error.
Andy idea what is going wrong
var ldr:URLLoader = new URLLoader();
ldr.dataFormat = URLLoaderDataFormat.TEXT;
var strData:String = "{\"gparam\": [ {\"productid\": \"" + productId + "\"},{\"message\": \"" + mesage + "\"},{\"googleappid\": \"" + googleappid + "\"},{\"senderid\": \"" + senderid + "\"},{\"appname\": \"" + appName + "\"},{\"userid\": \"" + userId + "\"},{\"receiverid\": \"" + receiverId + "\"} ]}";
var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json");
var req:URLRequest = new URLRequest("http://localhost/AndroidGCM/GCMNotification.svc/SendGCM");
req.requestHeaders.push(hdr);
req.method = URLRequestMethod.POST;
req.data = strData;
trace("data: " + req.data);
ldr.addEventListener(Event.COMPLETE,onComplete);
ldr.addEventListener(IOErrorEvent.IO_ERROR , onError);
ldr.addEventListener(SecurityErrorEvent.SECURITY_ERROR ,onSecurityErr);
ldr.load(req);
function onComplete(e:Event):void
{
trace("LOAD COMPLETE: " + ldr.data);
TextField(parMC.getChildByName("txtCheck")).appendText("\n LOAD COMPLETE: " + ldr.data);
}
function onSecurityErr(e:SecurityErrorEvent):void
{
trace("error: " + e.text );
}
function onError(e:IOErrorEvent):void
{
trace("error: " + e.toString());
}