Cannot view data returned by amfphp - actionscript-3

I've recently set up amfphp 2.2.1 on my win7pro (iis7.x) local host in the hope of getting away from XML between phph and Flash. I Followed the inital 'hello world' tut on amfphp website and everything was great.. it worked. My problem started when I tried querying a mySQL db.
my debug proxy says there is data being grabbed via amfphp/index.php (getAvailSvc/getBds) and it appears to be the data that I expected. When I try to view that data in Flash. When I try the simplest of functions
function handleResult(respond:Object):void{
trace(respond);
}
the trace give me [object Object],[object Object],[object Object]... etc
When I edit the trace to (respond.serverInfo.initialData) or my function to read the objects thus:
function handleResult(respond:Object):void{
var h:Array = respond.serverInfo.initialData;
for (var i:uint = 0; i < h.length; i++){
trace (h[i][0]);
}
}
I get the following error:
TypeError: Error #1010: A term is undefined and has no properties.
at amf_fla::MainTimeline/handleResult()
I've searched and searched the web for amfphp tuts and guidance but most, if not all, the stuff I found is circa 6-7 years old and relates only to mysql_query stuff and amfphp 1.9-. If anyone can help I'd appreciate your support and aplogise in advance if its me just being stupid.
debug proxy output:
#Ariel Sommeria-Klein - raised here as suggested

You get [object Object],[object Object],[object Object], because you are receiving an array of objects. In your AMF object, that would be "Content".
So if you try the following in your handleResult function:
trace(respond[0]);
you should see simply
[object Object]
and if you try the following:
trace(respond[0].name);
you should see
Abbeydale Independent

Related

feathers-blob error dauria can no read property startsWith

I just started using feathers-blob for uploading files from a angular4 client using dropzone.
I followed the example but made an explicit service for the upload not tu blur up the app.js.
It compiles without error, but on execution i receive the following error, even i do NOT use multipart portion:
Info: error:
system/file-upload - Method: create: Cannot read property 'startsWith'
of undefined error: TypeError: Cannot read property 'startsWith' of
undefined
at Dauria.parseDataURI (/projects/esaas-2/esaas-server-basic/node_modules/feathers-blob/node_modules/dauria/dauria.js:27:17)
at Object.create (/projects/esaas-2/esaas-server-basic/node_modules/feathers-blob/lib/index.js:87:52)
at /projects/esaas-2/esaas-server-basic/node_modules/feathers-hooks/lib/hooks.js:101:31
at /projects/esaas-2/esaas-server-basic/node_modules/feathers-hooks/lib/hooks.js:85:16
I also made sure to use the same versions of feathers-blob and dauria and multer as in the sample and not the newer ones from the npm. Result is the same.
What am i doing wrong? Any help appreciated. Thanks
If you look into dauria's code you'll see where the problem comes from:
Dauria.prototype.parseDataURI = function(dataURI){
if(!( dataURI.startsWith('data:') )) throw new Error(
this.errors.MISSING_PREFIX
);
Which means that somehow the value that you pass to the caller dauria.parseDataURI(yourDataVariable) - the yourDataVariable value does not start with 'data:'.
I made a test on Node and I had the same error while trying to upload an image. I solved it by adding the string "data:image/jpeg;base64" followed by the 64 encoded image.

AS3, Flash: Accessing error messages text in code

I'm working on some flash app. Now, to test customer side of it I can use Flash Player debugger version that will save logs and show error messages. When it's deployed on the customer side - they will have a regular Flash Player version which means I will have no access to error messages if errors will happen. So I would like to equip it with some tool that would capture all of my trace messages in code and errors text. As for trace messages that's fairly simple, I just override the function in my code so it sends a POST request with trace message to a logger server, but how can I get a hold of the error message? Is there a known approach to this or some trick that somebody can suggest?
You can install the debug version of flash as your browser's default (in Chrome, you must disable the built-in player), so if you wanted to test user experience and debug, this would be the ideal solution.
However, to answer your question: there's no method for universally catching all errors, and redirecting them (that I know of). You'd have to encapsulate problem code ahead of time with try...catch statements, and send the property back on catch. For example:
try {
this["foo"]();
} catch (e:Error) {
trace(e);
}
In the debug version, the traced value would be TypeError: Error #1006: value is not a function. And while the standard version will only output TypeError: Error #1006, (a notably less descriptive error), what we're missing is any reference to where the error occured. To get this, we need to use Error.getStackTrace() to see the call stack and the line where the error occurred. In debug, this outputs the following:
TypeError: Error #1006: value is not a function.
at Shell_fla::MainTimeline/init()[C:\Projects\shell.as:91
In the standard client, we get a dissapointing null. In short, you cannot get any valuable info from the client versions.
The best advice I can give is to write around your problem code with your own custom error reports. For example, catch IO errors and trace the file it failed to load, or if you're expecting an object.foo, first try if (object.hasOwnProperty("foo")) { // do something } else { trace("foo not found in " + object.name) }. Code defensively.
Cheers,
I've discovered this post on StackOverflow:
How to catch all exceptions in Flex?
It answers my question, strange that I haven't ran into it while I was googling prior to asking.

System.TypeInitializationException between two program in F#

I'm working on a project and I become always an Exception "TypeInitializationException".
I tried to give a string to a global string variable but it failed.
That's the code for the viewmodel and it failed on the second line
| {State = _}, ConsumablesClicked vm ->
Testtyp <- vm.TrackPosition.ToString()
That's on the other program
let mutable Testtyp = ""
I become this InnerException "Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.".
"The type initializer for '.$BarcodeGenerieren' threw an exception.", that's the exception explication.
Has someone a Idea how solve this?
That exception indicates that some code is trying to call Console.ReadKey when the standard input for that process has been redirected (see e.g. Allowing redirection of StandardInput of a C# application when doing "Console.ReadKey"). The solution is not to call Console.ReadKey, but it's not clear from your description where this is actually happening (perhaps in the static constructor for one of your types?).
I found the solution after a lot of try and it was only, that I had a Console.Readkey in my code, that I forgot to delete.
I had before a console apllication and I transformed it to be a class.

How to access returned JSON object from soundcloud api

I am trying to access a json object returned from soundcloud. I can access it using the following
var myJSON = $.getJSON("http://api.soundcloud.com/users/<myuserid hidden>/tracks.json?client_id=<myclientid hidden>");
now, I know all the data has been correctly assigned to the var myJSON, as when I log it to the console, everything is there. It returns something like this:
"[{"kind":"track","id":<trackid>,"created_at":"2012/12/17 21:48:03 +0000","user_id":<myid>,"duration":185147,"commentable":true,"state".......
However, when I try to access anything like, say, the title of the first track with:
console.log(myJSON[0].title);
chrome simply gives the error Uncaught TypeError: Cannot read property 'title' of undefined
so... I am probably missing something quite basic here. Anybody got any idea as to what I'm doing wrong? Help would be very much appreciated!
EDIT: everything needs to be done inside the $.getJSON call, as such:
$.getJSON('http://api.soundcloud.com/users/<userid>/tracks.json?client_id=<client_id>', function(sounds) { **enter whatever code you want to execuse
The "function(sounds)" part is what's important to add. Apparently, it's not very straightforward to access anything you get from the JSON object outside of the .getJSON method. (there are some ways, but require some workarounds that I didn't really understand much of). soo... I needed to add all my code inside here.

Using JSON templates in Play 2.0

I'm getting this error:
Compilation error [package views.json.Runs does not exist]
when it clearly does exist. I can't figure out what I could be doing wrong.
the action in the Runs controller:
#BodyParser.Of(play.mvc.BodyParser.Json.class)
public static Result view(Long task_id, Long run_id) {
Run run = Run.find.byId(run_id);
return ok(views.json.Runs.view.render(run));
}
app/views/Runs/view.scala.json:
#(run: Run)
{
"started": "#run.started",
"completed": "#run.completed"
}
I've gotten a few html templates working, but this is the first JSON template I've tried with 2.0. I'm not sure what else to try since it's already about as basic as possible. Anyone have any ideas?
Update: I've gotten several suggestions for workarounds, but I'm still interested in knowing how to get the templates working, if only to better understand the changes to 2.0.
Only html, xml and txt appear to be supported by default. For other file extensions and formats, you'd have to register additional "templateTypes" in $PLAY_HOME/framework/src/sbt-plugin/src/main/scala/PlaySettings.scala (see also: SBT Settings, near the bottom).
It may be helpful to look at the standard template types definitions which are in $PLAY_HOME/framework/src/play/src/main/scala/play/api/templates/Templates.scala.
You could also cheat and serve your json from a txt file, but do response().setContentType("application/json") before calling the render method.
For Json, why don't you directly produce a Json string using the Json helper:
public static Result view(Long task_id, Long run_id) {
Run run = Run.find.byId(run_id);
return ok(play.libs.Json.toJson(run));
}
I recommend following the documentation and let the Json library serialize your data instead of writing the Json text on your own: See Serving Json Response.
I still don't understand, why does people want to render theirs JSON with views.
Note: this is the same way as #nico_ekito showed before and I agree with him totally , below code just demonstrates how to select part of the object for JSON
public static Result view(Long task_id, Long run_id){
Run run = Run.find.byId(run_id);
ObjectNode result = Json.newObject();
result.put("started", run.started);
result.put("completed", run.completed);
return ok(Json.toJson(result));
}