Upload pre-selected file with actionscript - actionscript-3

I'm creating a photoshop extension where I need to save the file people are working on and upload it to a server. So I want the extension to be able to automatically choose the current file and upload it to my server.
Problem is I don't know how to pre-select a file for people. Here's my code so far:
var app:Application = Photoshop.app;
var doc:Document = app.documents.add();
doc.selection.selectAll();
var color:RGBColor = new RGBColor();
color.red = 0;
color.green = 0;
color.blue = 255;
doc.selection.fill(color);
var saveOptions:JPEGSaveOptions = new JPEGSaveOptions();
//Add other PDF save options here.
doc.saveAs(File.applicationStorageDirectory, saveOptions);
var jsonOBJ:Object = {};
jsonOBJ.option = "iphone";
jsonOBJ.title = "c";
jsonOBJ.description = "s";
jsonOBJ.app_store_url = "iphone";
jsonOBJ.tags = "c";
jsonOBJ.temp_number = 1;
var _service:HTTPService = new HTTPService();
_service.url = "http://localhost:3000/designs";
_service.method = "POST";
_service.contentType = "application/json";
_service.resultFormat = "text";
_service.useProxy = false;
_service.makeObjectsBindable = true;
_service.addEventListener(FaultEvent.FAULT,faultRX);
_service.addEventListener(ResultEvent.RESULT,resultRX);
_service.showBusyCursor = true;
_service.send( JSON.encode( jsonOBJ ) );
function resultRX():void
{
trace(ResultEvent.RESULT);
}
function faultRX():void
{
trace(FaultEvent.FAULT);
}
var file:FileReference;
var filefilters:Array;
var req:URLRequest;
filefilters = [ new FileFilter('Images', '*.jpg') ]; // add other file filters
file.browse(filefilters);

It's a photoshop extension. I ended up using FileReference and link to the file. it worked. I dunno how to actually upload the image though. When I use file.upload(requestUrl), it sends along a wrong content type. –

Related

Cannot add created label to threads

I tried to write a function in Google Apps Script that creates a new label in Gmail and adds it to threads.
I have two problems:
When I run the function for the first time (archivedLabel not existing yet) I cannot add it to the threads immediately after it is created.
archivedLabel = GmailApp.getUserLabelByName(labelText) at the end of the if statement will still return null and the script crashes.
If I run the script for the second time (label already created) everything works fine.
The new labels only appear in Gmail after the user refreshes the Gmail App in the browser. Is there a way to do this automatically or a method to refresh the labels and messages so I can see the new label in Gmail without manually reloading the page?
function addArchivedLabel(thread){
var labelText = "Backed up";
var archivedLabel = GmailApp.getUserLabelByName(labelText);
//create new archived label if not already existing
if(archivedLabel == null) {
var textColor = "#89d3b2"; // Please set this.
var backgroundColor = "#ffbc6b"; // Please set this.
var userId = "me";
var resource = Gmail.newLabel();
resource.labelListVisibility = "labelShow";
resource.messageListVisibility = "show";
resource.name = labelText;
var labelColor = Gmail.newLabelColor();
labelColor.textColor = textColor;
labelColor.backgroundColor = backgroundColor;
resource.color = labelColor;
Gmail.Users.Labels.create(resource, userId);
archivedLabel = GmailApp.getUserLabelByName(labelText);
}
archivedLabel.addToThread(thread); //add new label to archived emails
}
I just encountered the same problem
For some reason this is working :
function getOrCreateLabel() {
if (!GmailApp.getUserLabelByName(LABEL_NAME)) {
GmailApp.createLabel(LABEL_NAME)
}
console.log(GmailApp.getUserLabelByName(LABEL_NAME)) // not NULL
}
And this is not working as expected:
function getOrCreateLabel() {
if (!GmailApp.getUserLabelByName(LABEL_NAME)) {
Gmail.Users.Labels.create({
"labelListVisibility": "labelHide",
"messageListVisibility": "hide",
"name": LABEL_NAME
}, "me")
}
console.log(GmailApp.getUserLabelByName(LABEL_NAME)) // NULL
}
For the second function,It seems that appsscript cache the response of GmailApp.getUserLabelByName at runtime.
So in my opinion. You will need to create a trigger, here a working exemple:
function addArchivedLabel(thread){
var labelText = "Backed up";
var archivedLabel = GmailApp.getUserLabelByName(labelText);
const thread_id = UserProperties.getProperty("thread")
// Check if come from trigger
if (thread_id) {
// retrieve the thread
thread = GmailApp.getThreadById(thread_id)
// Clean property and trigger
UserProperties.deleteProperty("thread")
ScriptApp.getScriptTriggers().forEach((p) => {
if (p.getHandlerFunction() == "addArchivedLabel") {
ScriptApp.deleteTrigger(p)
}
})
}
//create new archived label if not already existing
if(archivedLabel == null) {
var textColor = "#89d3b2"; // Please set this.
var backgroundColor = "#ffbc6b"; // Please set this.
var userId = "me";
var resource = Gmail.newLabel();
resource.labelListVisibility = "labelShow";
resource.messageListVisibility = "show";
resource.name = labelText;
var labelColor = Gmail.newLabelColor();
labelColor.textColor = textColor;
labelColor.backgroundColor = backgroundColor;
resource.color = labelColor;
Gmail.Users.Labels.create(resource, userId);
UserProperties.setProperty("thread", thread.getId())
ScriptApp.newTrigger("addArchivedLabel").timeBased().everyMinutes(1).create()
return
}
archivedLabel.addToThread(thread); //add new label to archived emails
}
// fixture to simulate get thread
function main() {
const thread = GmailApp.getInboxThreads()
addArchivedLabel(thread[0])
}
Hope it will help

LimeJs HTML5 Sound on Chrome breaks my file

I have just start learning LimeJS, but i have a problem with the sound, when i open it in firefox i have not problem but when i open it in chrome the game stop working and doesnt show, i dont know why, i try to fix it and now i can see the objects but i cant drag them, is like it stop . here is the code, I hope you can help me
//set main namespace
goog.provide('bichos');
//get requirements
goog.require('lime');
goog.require('lime.Director');
goog.require('lime.Scene');
goog.require('lime.fill.LinearGradient');
goog.require('lime.Sprite');
goog.require('goog.math');
goog.require('lime.GlossyButton');
goog.require('lime.audio.Audio');
goog.require('lime.Layer');
goog.require('bichos.Bug');
goog.require('lime.Label');
// entrypoint
bichos.start = function(){
var director = new lime.Director(document.body,480,320);
director.makeMobileWebAppCapable();
director.setDisplayFPS(false);
var scene = new lime.Scene().setRenderer(lime.Renderer.DOM);
var initialscene = new lime.Scene().setRenderer(lime.Renderer.DOM);
//InitialScene
var initialLayer = new lime.Layer().setPosition(0,0).setAnchorPoint(0,0);
var initialContainer = new lime.Sprite().setAnchorPoint(0,0).setPosition(0,0).setFill('#EEE0E5').setSize(480,320);
var initialTitle = new lime.Label().setText('Welcome').setFontFamily('Arial').setFontColor('#000000').setFontSize(20).setPosition(240,60);
var startButton = new lime.GlossyButton().setSize(200,60).setPosition(240,150).setText('Start').setColor('#00cD00');
initialscene.appendChild(initialLayer);
initialLayer.appendChild(initialContainer);
initialLayer.appendChild(initialTitle);
initialLayer.appendChild(startButton);
//director
director.replaceScene(initialscene);
//evento inicial
goog.events.listen(startButton,['mousedown','touchstart'],function(e){
e.event.stopPropagation();
director.replaceScene(scene);
});
//Grass
var grass_gradient = new lime.fill.LinearGradient().setDirection(0,0,1,-1).addColorStop(0,'#7CCD7C').addColorStop(1,'#00FF00');
var grass = new lime.Sprite().setSize(480,320).setPosition(0.0).setAnchorPoint(0,0).setFill(grass_gradient);
//caja
var box = new lime.Sprite().setAnchorPoint(0,0).setPosition(390,230).setFill('img/Box01.png').setSize(80,80);
//contar
var num_bugs_catched = 0;
var bug_count = new lime.Label().setText('Bug Count: '+num_bugs_catched).setFontFamily('Arial').setFontColor('#000000').setFontSize(20).setPosition(100,300);
scene.appendChild(grass);
scene.appendChild(box);
//Insectos
var num_bugs =goog.math.randomInt(10)+1;
var x,y,bug;
for(var i = 0; i < num_bugs; i++){
bug = new bichos.Bug();
bug.crawl();
scene.appendChild(bug);
//sound
var bugSound = new lime.audio.Audio('audio/bug.ogg');
//eventos
goog.events.listen(bug,['mousedown','touchstart'],function(e){
var drag = e.startDrag();
drag.addDropTarget(box);
e.event.stopPropagation();
bug = this;
goog.events.listen(drag,lime.events.Drag.Event.DROP, function(e){
//play sound
bugSound.stop();
bugSound.play();
num_bugs_catched++;
bug_count.setText('Bug Count: '+num_bugs_catched);
//Desaparecer bichos
bug.setHidden(true);
delete bug;
//Tambien se puede usar window.location='';
if(num_bugs_catched == num_bugs){
alert('Has Ganado!');
bichos.start();
}
})
})
}
scene.appendChild(bug_count);
// set current scene active
}
//this is required for outside access after code is compiled in ADVANCED_COMPILATIONS mode
goog.exportSymbol('bichos.start', bichos.start);

Problems loading XML file (url cannot load) on local machine

I'm trying to have my flash application interpret an XML file. My code looks like:
function onFinish(success_boolean, results_obj, xml)
{
if (success_boolean)
{
play ();
} // end if
} // End of the function
Stage.align = "MC";
Stage.scaleMode = "noScale";
url = "25358";
_root.cacheKiller = "true";
stop ();
var parsed_obj = {};
var unCash = new Date().getTime();
if (_root.cacheKiller == "true")
{
fileToLoad = url + "_main.xml?cacheKiller=" + unCash;
fileToLoad = url + "_main.xml";
}
else
{
fileToLoad = url + "_main.xml";
} // end else if
gs.dataTransfer.XMLParser.load(fileToLoad, onFinish, parsed_obj);
_root.emp.useHandCursor = 0;
_root.mus = 1;
_root.n = 1;
_root.num = 1;
the output i get is:
Error opening URL 'file:///C|/try/25358undefined'
Does anyone have any idea why i can't access this file? I've verified that the URL works.
You have a wrong url. I mean that fileToLoad contains a wrong value. Try to trace this variable.

upload file to box api v2 using as3

I'm trying to upload file to box using v2. The only result i get is the error while uploading. I'm able to authenticate, get the auth token but not able to upload, I have given the code which i'm using. If i'm wrong anyway just correct me. Any help will be appreciated!!
public function upload(argFile:flash.filesystem.File):void{
argFile.addEventListener(Event.COMPLETE,
function onComplete(event:Event):void
{
trace("complete:"+event.toString());
}
);
argFile.addEventListener(IOErrorEvent.IO_ERROR,
function onIOError(event:IOErrorEvent):void
{
trace("Error:"+event.toString());
}
);
var url:String = "https://api.box.com/2.0/files/data";
// Setup the custom header
var customHeader:String = "BoxAuth api_key=" + api_key + "&auth_token=" + auth_token;
var headers:Array = [
new URLRequestHeader("Authorization", customHeader)
];
// create the url-vars
var urlVars:URLVariables = new URLVariables();
urlVars.filename1 = '#'+argFile.name;
urlVars.folder_id = "0";
// create the url-reqeust
var request:URLRequest = new URLRequest();
request.contentType = "application/octet-stream";
request.method = URLRequestMethod.POST;
// set ther url
request.url = url;
// set the header
request.requestHeaders = headers;
// set the vars
request.data = urlVars;
try {
argFile.upload(request);
} catch (e:Error)
{
trace(e.toString(), "Error (catch all)");
}
}

Icon Field on List

I load label and icon from mysql database.
and i'd like to create a list with label and icon field.
So I try to do something like that but it doesn't work indeed each line contain label but icon is empty.
var xmllisteFamille:XMLList = XML(event.result).famille;
var xmlListCollFami = new XMLListCollection(xmllisteFamille);
for each (var item:Object in xmlListCollFami){
var vbox:VBox = new VBox;
vbox.label = item.sdfNom;
trace(vbox.label);
vbox.percentHeight=100;
vbox.percentWidth=100;
var xmlItem2:XMLList = item.commDent;
if(xmlItem2.length()>0){
/*
var listAcc:List = new List();
listAcc.percentHeight = 100;
listAcc.percentWidth =100;
listAcc.labelField = "name";
listAcc.dataProvider = xmlItem2;
vbox.addChild(listAcc);
accOnglet1.addChild(vbox); */
var urlImageRoot : urlManager = new urlManager();
var urlRootDental:String = urlImageRoot.urlDental();
trace(urlRootDental);
var list:Array = new Array();
var object:Object;
var xmlListdetail:XMLListCollection = new XMLListCollection(xmlItem2);
for each (var item2:Object in xmlListdetail)
{
object = new Object();
// -- --
object.label = item2.name;
var rootIcon:String= "http://127.0.0.1:10088/Sys/OEMySQL/Dental/"+item2.photo;
trace("rootIcon " + rootIcon);
object.icon = rootIcon;
trace("object.icon " + object.icon);
list.push(object);
}
/* var aNode:XML;
for each (aNode in xmlItem2)
{
object = new Object();
// -- --
object.label = aNode.name;
object.icon = new urlManager().urlDental()+aNode.photo;
list.push(object);
} */
var arrList:ArrayList;
arrList = new ArrayList(list);
var listAcc:List = new List();
listAcc.percentHeight = 100;
listAcc.percentWidth =100;
listAcc.labelField = "label";
listAcc.iconField="icon";
//listAcc.dataProvider = xmlItem2;
listAcc.dataProvider = arrList;
vbox.addChild(listAcc);
accOnglet1.addChild(vbox);
}
}
}
}
I hope that you can help me.
Thanks
it may be crossdomain issue
you need to know if flash player requires crossdomain.xml in this case
use charles proxy to check what exactly you are sending to server (request) and getting back from server (response)
charles proxy website
I found the solution.
I had to create an itemrenderer and add it in as3 to my list.
thanks