Load Actions from Javascript - adobe

I have an Adobe Illustrator action file (.aia) that I'd like to load in the extension builder environment via .js or .jsx. I noticed that there is app.loadAction() - but I can't get the operations to work. If I have the action file stored in my root folder, how do I get the actions to load in Illustrator?

Below is the setup I got working. This extension uses HTML panels, with a button click, we load an action into Illustrator. The button click triggers the JS function below which then calls to the JSX script. The .aia file is stored in the root folder, ./assets
JS function:
function getActionFile() {
var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/assets/Utility.aia"; //exported aia file
csInterface.evalScript('loadActions('+JSON.stringify(extensionRoot)+')');
}
JSX function:
function loadActions(f){
var scriptFile = File(f);
app.loadAction(scriptFile)
}

Related

Why can't I access JS functions made in separate JS files in my html when using Meteor

Meteor says when you write some javascript in a JS file, every file automatically has access to it everywhere in the app, but when I write a function in a a separate file like that, I just get a console error saying that function could not be found when I call it in html. The only way I can get it to work is by writing the JS in the html file but I want to keep the languages separate. Any idea on what the problem is?
code:
html in one file:
<button onclick="dylan()"></button>
js in another file:
function dylan(){
console.log("hello");
}
the problem is, when I click the button, it says dylan is not a function.
Meteor docs do not spell this out but every individual javascript file is wrapped into a closure:
(function() { //the file content // })()
so all functions in a given file have their own scope.
Functions defined in a js file in Meteor normally only have file scope - that is, any object in that file can refer to them.
If you want to define a global function, create a global variable:
dylan = function(){
...
}
Note the absence of let or var which would restrict the function to file scope.
Now you can use this global in your onclick handler.
Note however, that normally in Meteor, you would define an event handler at the template level, ex:
Template.myTemplate.events({
'click button'(){
...your code here
}
});
As opposed to referring to event handlers in your html directly.
The purpose of using Meteor is not met if you do not harness the wonderfull features such as
Template.X.events({});,
Template.X.helpers({}); and also
Template.registerHelpers({});
You can write your desired code in below way:
Template.template_name.events({
'click .button_class' : function() {
console.log("Hello");
}
});
//HTML
<button class="button_class"></button>
If that click event has to be used in more than 1 HTML then you can use registerHelper methods than template click events.
Template.registerHelpers('dylan' : function() {
console.log("Hello");
});
//html
<button onclick="dylan"></button>
To access dylan(), you must first load the script file that contains that function into the html document.
You can do this by adding <script src="myfile.js"></script> anywhere before the button. (replace myfile with the name of your script)
Once loaded, <button onClick="dylan()"></button> will work!

Meteor Upload to AWS S3

I have a Meteor app in which I insert a document (title, description, customer, ...) into a database. The app is using Autoform, Simple Schema and Collection2. I now want to add the possibility to upload a file to S3.
To keep things simple, I would present a filepicker as part of the 'Create Document' and once the file is uploaded, the URL field (from Autoform), should show the URL of the document on S3 (once uploaded) so that the URL is eventually stored in the document collection when the create button is clicked. I realise there might be better ways, but wanted to keep things simple for now.
I have tried to combine the tutorial here. The upload to S3 works, but I fail to get the URL for the uploaded file stored documents collection. The below screenshot shows the layout. Any idea's?
My current code can be found here.
There appear to be autoform add-on packages that specifically address S3 file upload (see the "Files" section here), but since you seem to be using this as learning opportunity, I'll try to explain how I'd do it using core meteor.
But first, before I forget, your uploader template is a child of #autoForm but has a form element of it's own. I think that will cause the generated HTML to have nested form elements (which is no-no). To fix that, I'd move the {{/autoForm}} before the {{> uploader}} and add an event handler for your submit button that submits the form using $('#documentForm').submit(). Note: I haven't tested that.
Now, on to your actual question. You are essentially asking how to modify something in a template (the value of the url field) from an event in a nested template (the uploader template). I'd do that as follows:
When an instance of the parent template is created, attach a ReactiveVar to it that will hold the URL of the uploaded file.
Template.adminDocumentNew.onCreated(function () {
this.url = new ReactiveVar();
});
Provide a helper to get the reactive var.
Template.adminDocumentNew.helpers({
url: function () {
return Template.instance().url;
}
});
Use the helper to set the value in the form.
{{> afQuickField name='url' value=url.get}}
Pass the reactive var to the uploader template as the data context:
{{> uploader urlVar=url}}
Use the reactive var to set the URL when the upload finishes (somewhere in upload-to-amazon-s3):
template.data.urlVar.set(url);
I've created a meteorpad that demonstrates the basic idea outside of the context of autoform and S3.

execute javascript after documentLibrary is fully loaded alfresco

I want to trigger a javascript function after all the documents in the document library are loaded.
I have coded a custom renderer for document library to display custom text for document library. When all the contents of the document library are loaded, I want to execute a javascript on the custom text.
I tried the below code in custom javascript file added as dependency and it does not work.
$(document).ready(function () {
myjsfunction();
}
I am using a window.setInterval to call cutom javascript function after a predefined time

jQuery Script is not executing after a button click in update panel

I have a button inside a update panel, & I am using jQuery scripting to style the elements in the page. Initially the page loads & css style applies on it along with the script which have some jQuery code. i.e. Initially everything is OK. But when I click on the button it causes a server post-back(necessary), the CSS style is applied but Script is not loaded. Please help me out with this.
Add this to your script (if using .Net 3.5 or less). It will notify the Microsoft Ajax Library that the JavaScript file has been loaded.
if (typeof (Sys) != 'undefined')
{
Sys.Application.notifyScriptLoaded();
}
Note: This is obsolete in .Net 4
You need to run your code (best as a named function) as part of the endRequest event as well, for example you can have a named function like this:
function doStuff() {
//do whatever here
}
Then run that function where needed:
//run on DOM ready
$(doStuff);
//also run it when UpadtePanels finish/reload
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(doStuff);

ActionScript 3 - a loader that supports many apps?

I have created a simple SWF-loader in ActionScript 3.0. It loads an SWF from a server and then plays it. While downloading, it displays the "loading" screen.
Its main defect is that it can load only one Flash application - the one which it is compiled for. Let's say it's named test1.swf.
Is there any way to make the loader support more than one Flash app (for example test2.swf and test3.swf)? I mean by passing external parameters to it and not by creating another loader. Is using Javascript the only way to do it? I don't want my loader to require the Javascript support.
And I really don't want to create separate loaders for all of my apps...
Thanks in advance.
In order to load an external SWF your loader only need the url of the swf to be loaded, this url doesn't have to be hardcoded. There are many ways to pass parameters to a SWF file and they don't necessarily require Javascript.
You could load a XML file for instance, a simple text file would work too , you could also use a PHP script. Using flahsvars would require Javascript, although only to set your application in your HTML page.
With the following example , your app doesn't need to recompile , you simply change the url in the text file.
Example with a text file containing a url, something like this:
http://yourwebsite.com/test1.swf
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE , completeHandler );
urlLoader.load( new URLRequest('swfURL.txt') );
function completeHandler(event:Event):void
{
loadExternalSWF(event.target.data );
event.target.removeEventListener(Event.COMPLETE , completeHandler );
}
function loadExternalSWF(url:String ):void
{
//your code here , using the url value
trace(url );//should return your text file content
}

Resources