FDT: Could not resolve variable (may be an XML element name) - actionscript-3

I'm getting some warning signs in FDT in a couple of lines of code that access values in the app descriptor, like this:
var appDescriptor:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = appDescriptor.namespace();
var appId:String = appDescriptor.ns::id[0];
var appVersion:String = appDescriptor.ns::versionNumber[0];
Those lines work fine, but FDT underlines "id" and "versionNumber", and issues the warning "Could not resolve variable (may be an XML element name)".
Is there a way to get rid of that warning?

Sort of, you can use this snippet:
/*FDT_IGNORE*/
// your code
/*FDT_IGNORE*/
to have FDT ignore the code therein. Another option is to try these settings. Otherwise try different parser / error settings to see what happens.
Preferences http://dl.dropbox.com/u/154189/web/never/Preferences.png

Related

How to I save text from a document into a variable?

I want to take the text for a document and save it as a variable. I looked in the documentation and found "getText" something I think shall work. https://developers.google.com/apps-script/reference/document/footnote-section#gettext
I just get a problem when I try using it, because it's not a pre built function it gives the error massage "TypeError: Cannot read property 'getText' of null". So I looked at some more into it and noticed I needed Authorization:
"Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents"
So how do I get the required authorization, do I need to do something different or is there another way i could do it?
It's just going to run on some of my docs for fun to se what funny things I am able to do with the program.
(New to programing, now the basics but just trying to see if programing is something for me)
Thanks in advance
Given with this sample document
You can start with this sample code below.
Code:
function myFunction() {
var body = DocumentApp.getActiveDocument().getBody();
var text = body.editAsText();
Logger.log(text.getText()); // returns all text in document ("Hey, search for me!!! I am <here>!!")
// 1. Regular expression (exec)
var regExp = new RegExp("<\(.*\)>", "gi"); // "i" is for case insensitive
var search = regExp.exec(text.getText())[1];
Logger.log(search); // returns "here"
// 2. (search)
Logger.log(text.getText().search(/here/)); // returns the index where the string was found, or -1 if not found
}
Output:
Note:
getText will return the text of the Class Text.
If you want to get a specific pattern from the document, you need to use Regular expression. I prefer the exec method. See usage for more details
For the authorization, you only need to click allow. I assume you are using apps script due to the tag.

How do I extract metadata from a var when a function returns its symbol?

I'm using re-frame with spec to validate app-db, much like in the todomvc example.
When a user makes an invalid entry, I'm using s/explain-data (in a re-frame interceptor) to return a problems map naming the :predicate which caused validation failure. This predicate is a symbol like project.db/validation-function.
My validation function has metadata which is accessible from the repl using:
(meta #'project.db/validation-function)
The function definition (in the project.db namespace) looks like this:
(defn validation-function
"docstring..."
{:error-message "error message"}
[param]
(function-body...)
The problem is I can't work out how to retrieve the metadata dynamically (working in project.events namespace), for example:
(let [explain-data (s/explain-data spec db)
pred (->> (:cljs.spec.alpha/problems explain-data) first :pred)
msg (what-goes-here? pred)]
msg)
I've tried the following things in place of what-goes-here?:
symbol? gives true
str gives "project.db/validation-function"
meta gives nil
var gives a compile-time error "Unable to resolve var: p1__46744# in this context"
I think the problem is that I'm getting a symbol, but I need the var it refers to, which is where the metadata lives.
I've tried using a macro, but don't really know what I'm doing. This is the closest discussion I could find, but I couldn't work it out.
Help!
In general, you can't do this because vars are not reified in ClojureScript.
From https://clojurescript.org/about/differences#_special_forms :
var notes
Vars are not reified at runtime. When the compiler encounters the var special form it emits a Var instance reflecting compile time metadata. (This satisfies many common static use cases.)
At the REPL, when you evaluate
(meta #'project.db/validation-function)
this is the same as
(meta (var project.db/validation-function))
and when (var project.db/validation-function) is compiled, JavaScript code is emitted to create a cljs.core/Var instance that contains, among other things, the data that you can obtain using meta. If you are curious, the relevant analyzer and compiler code is instructive.
So, if (var project.db/validation-function) (or the reader equivalent #'project.db/validation-function) doesn't exist anywhere in your source code (or indirectly via the use of something like ns-publics) this data won't be available at runtime.
The omission of var reification is a good thing when optimizing for code size. If you enable the :repl-verbose REPL option, you will see that the expression (var project.db/validation-function) emits a significant amount of JavaScript code.
When working with defs at the REPL, the compiler carries sufficient analysis metadata, and things are done—like having evaluations of def forms return the var rather than the value—in the name of constructing an illusion that you are working with reified Clojure vars. But this illusion intentionally evaporates when producing code for production delivery, preserving only essential runtime behavior.
edit: sorry I didn't see that var didn't work for you. Still working on it...
You need to surround the symbol project.db/validation-function with var. This will resolve the symbol to a var.
So what-goes-here? should be
(defn what-goes-here? [pred]
(var pred))

How can I reference a Flash file's own filename from actionscript?

In our pipeline, we ultimately publish HTML5 using Toolkit for CreateJS. However one of the steps to get us to that HTML5 includes publishing an SWF that outputs some Javascript code. I've mostly managed to automate this using JSFL. However, at present there is one line of AS3 that our artists have to find on the timeline and change manually, but it interrupts their workflow, and if they miss it or mess it up it is hard to catch, so I would like to automate it too:
Object(root).log.text += " root.skillAnime189 = factory();\n";
From the above, "skillAnime189.fla" is the name of the .fla file which contains this code. This is the case if the artist is working on Skill Animation #189, but if he is doing #304 or #6 or #1022 (no padding) the number changes accordingly, and he has to update that line accordingly.
So, I would like to change that line to something like:
var flaName:String = getThisFlashFileName().split(".")[0];
Object(root).log.text += " root." + flaName + " = factory();\n";
but I am at a loss as to how to access the name of the .fla file containing the code.
The common way to get the swf name is to parse stage.loaderInfo.url parameter:
var url:String = stage.loaderInfo.url;
url = url.split("?")[0]; //remove query string after "?"
var swfname:String = url.substring(url.lastIndexOf("/")+1);
trace(swfname);
output:
astest.swf
But this code gives swf but, rather than fla, so you need to maintain the same names for flas and published swfs (any case usually they are the same, so it shouldn't be the problem)

Converting circular structure to JSON -- Any way to find what field it is complaining about?

I'm trying to stringify(...) an object in Chrome, and I keep getting a "Converting circular structure to JSON" message, despite the fact that (as far as I know) no such structure exists.
I've been over the code a dozen times and can't find any circular references whatsoever. Is there any way to get Chrome to tell me what it's bitching about beyond this painfully useless error message?
Pardon me if this is too obvious. At the time of writing, I dont know what you have tried.
insert
console.log(the object);
replacing 'the object' with the object you are passing to JSON.stringify()
insert this line before the JSON.stringify call
and look in the console log (shift control J) for the object. In the console log the object will be tagged with a ">" symbol which can be clicked to expand to the fields.
It is complaining about an object that has pointers into itself, like this kind of object:
A = [];
A[0] = A;
JSON.stringify(A); // circular error
You can use dojox.json.ref to find circular references. This code prints json representation of your objectWithCircularReferences:
require(["dojox/json/ref"], function(){
console.log(dojox.json.ref.toJson(objectWithCircularReferences));
});
Any occurence of "$ref" substring in its output to console will help you locate circular references. You can alternatively pipe this json output to global variable ZZZ like this if you wish:
require(["dojox/json/ref"], function(){
window.ZZZ = dojox.json.ref.toJson(objectWithCircularReferences);
});
And of course you need to include dojo library beforehand. In an html file:
<script src="//yandex.st/dojo/1.9.1/dojo/dojo.js"></script>
In firebug console:
include("//yandex.st/dojo/1.9.1/dojo/dojo.js")
In Chrome console:
SCRIPT = document.createElement('script');
SCRIPT.src = '//yandex.st/dojo/1.9.1/dojo/dojo.js';
document.body.appendChild(SCRIPT);

Actionscript add strings to embedded images?

Say I have something like this:
[Embed(source='../lib/images/image01.png')] var Image:Class
But I want to change that images based on another string like so:`
var StringData:String
StringData = "02";
[Embed(source='../lib/images/image'+ StringData +'.png')] var Image:Class
But this gives me an error, is there another way to do something like this?
Embedded resources are evaluated at compiling time so you can't set a dynamic path.
If you want a unique path by compile type (debug / release for exemple), you can use compiler variables :
[Embed(source=CONFIG::ICON_PATH)]
var Image:Class;
And add compiler args:
-define+=CONFIG::ICON_PATH,'../lib/images/image01.png'
or
-define+=CONFIG::ICON_PATH,'../lib/images/image02.png'