AS2 Attaching a Bitmap to Dynamic created Variables - dynamic

I'm stuck with this problem and simply cannot get it solved, sorry if there was another post about this already but I couldn't find it as well.
On to the problem then: I'm trying to make a simple function capable of initializing and updating bitmaps, and a few other variables I haven't thought of yet, when needed.
I created on the stage some MovieClips called slot0, slot1, slot2 etc... inside another MovieClip called ButtonRootPannel in order to have a visual of where I'll be putting the images without having to guess numbers in the code.
Together with those I set up this code:
var buttons_rootArray:Array = new Array;
for(var i=0;i<=11;i++){
this["slot"+i] = this.ButtonRootPannel.createEmptyMovieClip("slot"+i, i);
this["slot"+i].customState = "Inactive"; //Active, Inactive or Unavaiable
this["slot"+i]._x = eval("_root.ButtonRootPannel.slot"+i)._x;
this["slot"+i]._y = eval("_root.ButtonRootPannel.slot"+i)._y;
this["slot"+i]._width = eval("_root.ButtonRootPannel.slot"+i)._width;
this["slot"+i]._height = eval("_root.ButtonRootPannel.slot"+i)._height;
buttons_rootArray.push(this["slot"+i]);
}
UpdateButtonsSlot(0,"BuildButton");
UpdateButtonsSlot(1,"CancelButton");
function UpdateButtonsSlot(slot:Number, newImage:String):Void{
var tempData:BitmapData = BitmapData.loadBitmap(newImage);
var tempClip:MovieClip = eval(buttons_rootArray[slot]);
//buttons_rootArray[slot].unloadMovie();
//buttons_rootArray[slot].clear();
tempClip.attachBitmap(tempData,this.getNextHighestDepth(),"auto",true);
}
Anyone knows what I might be doing wrong?
Thanks in advance.

Well, problem solved, this now seems to be working for some strange reason:
for(var i=0;i<=11;i++){
var currentMC = eval("_root.ButtonRootPannel.slot"+i);
this["slot"+i] = this.ButtonRootPannel.createEmptyMovieClip("slot"+i, i);
this["slot"+i].customState = "Inactive"; //Active, Inactive or Unavaiable
this["slot"+i]._x = currentMC._x;
this["slot"+i]._y = currentMC._y;
//this["slot"+i]._width = currentMC._width;
//this["slot"+i]._height = currentMC._height;
buttons_rootArray.push(this["slot"+i]);
}
Only those commented lines makes the MovieClip disappear if I uncomment them. Will just leave them out then and problem solved.

Related

Illustrator variables - dynamically line up two text strings next to each other when autogenerating

I am automating the generation of several thousand labels in Adobe Illustrator. The use of the VariableImporter script has made easy work of it so far, but now I have reached an issue where I am stumped. The original plan worked great, until the powers that be requested that one line of text have a bold text string, followed by a normal weight text string. Before, when the font weights were the same I could have connected the two strings of text in the CSV file prior to loading them into the drawing, and they would have came out lying right next to each other. This is now no longer possible and I can't think of a solution that is not incredibly fussy.
I don't know illustrator very well, so I am thinking I could just be unaware of some setting that would stick an object next to another one even as the other one moves.
Okay here is the way I figured out how to do this with help from Adobe forums and from Vasily.
First of all, use InDesign if possible. It is better at performing a Data Merge and can do this without your scripting.
Write out <variable1> <variable2> which is formatted as needed on the same line of text.
You will need to have the variables that you are putting in there somewhere in the illustration. Recommended to put it in a hidden layer behind everything.
replace variable1 and variable2 with the names of your variables where the functions getVariableContents() are called in this script
var idoc = app.activeDocument;
var vars = idoc.variables;
var replace1 = /<variable1>/g;
var replace2 = /<variable2>/g;
// author CarlosCanto on adobe forums
function getVariableContents(variableName) {
var idoc = app.activeDocument;
var ivar = idoc.variables.getByName(variableName);
return ivar.pageItems[0].contents;
}
var replaceWith1 = getVariableContents('variable1'), result;
var replaceWith2 = getVariableContents('variable2'), result;
// regex_changeContentsOfWordOrString_RemainFormatting.jsx
// regards pixxxel schubser
function exchangeWords(s, replacer) {
var s = s;
var replacer = replacer;
var atfs = activeDocument.textFrames;
for (var i = atfs.length - 1; i >= 0; i--) {
atf = atfs[i];
while (result = s.exec(atf.contents)) {
try {
aCon = atf.characters[result.index];
aCon.length = result[0].length;
aCon.contents = aCon.contents.replace(s, replacer);
} catch (e) {};
}
}
}
exchangeWords(replace1,replaceWith1);
exchangeWords(replace2,replaceWith2);
run the script
There is a way to accomplish this by having a script do some processing during the course of your batch output, and an organizational system which adds some overhead to your file, in terms of adding more text boxes and possibly an extra layer to your document. But - here's what you can have: a hidden layer with all your variables there in separate single point-text objects, and a layer with your regular template objects such as any point text or area-text objects. Your art text objects will need to be re-worked to contain a string with multiple variable placeholders like this: "Hello, <FirstName> <LastName>". The placeholders can be styled, and a processing script would then need to replace the <placeholder> words with your real variable values. Where are the varible values? They are going to be populating into your hidden layer which has your separate text objects and the script would need to read the contents of each of those to put into the <placeholders>. ~~Those same text fields can be styled as you wish, and the script could apply the same styles to your text when it is replaced in the main text body.~~ -actually this won't be necessary of your routine backs up the original text frame with the placeholder in it, therefore preserving the styling, but it may be necessary if you are going to instead use an external text file to keep your original text in. And of course, it will need to make a backup of the original text with all the <placeholders> so that it will reset the text for every new dataset during your batch process.
However, this is much easier done in Indesign, can you not use ID for your task?
I modified script from #tucker-david-grebitus's answer. So now it gets all textual variables and replaces all their names edged by percent symbol
for (var i = activeDocument.variables.length - 1; i >= 0; i -= 1) {
var variable = activeDocument.variables[i];
if (variable.kind !== VariableKind.TEXTUAL || !variable.pageItems.length) {
continue;
}
var search = new RegExp('%' + variable.name + '%', 'g');
var value = variable.pageItems[0].contents;
for (var j = activeDocument.textFrames.length - 1; j >= 0; j -= 1) {
var textFrame = activeDocument.textFrames[j];
textFrame.contents = textFrame.contents.replace(search, value);
}
}

Alfresco PDF-Toolkit Javascript

i've recently installed Alfresco's PDF-Toolkit. My actual intension is to use it in a Javascript manner. This is because the value i need or want to watermark will be based on the Document's Property/Aspect.
i failed to find any tutorial or guide regarding this issue. if anyone can please give me a walkthrough, i'd really appreciate it.
my current script looks like this:
var watermark_action = actions.create("pdf-watermark");
watermark_action.parameters["destination-folder"] = ????;
watermark_action.parameters["watermark-type"] = "text";
watermark_action.parameters["watermark-text"] = aspect.ajie;
watermark_action.parameters["watermark-pages"] = "all";
watermark_action.parameters["watermark-depth"] = "over";
watermark_action.parameters["position"] = "center";
watermark_action.execute(document);
NOTE: i actually found one, the problem is that this one is an image watermark and what i want or need is a text watermark. also i need the script to save the watermarked copy to the same directory which i believe is not what the guide seems to do.
the last thing i need is the value for the destination-folder parameter. i really have no clue on how or what i'll place here just to save the pdf to the same folder. hoping to get some guide, tips, and tricks here. thanks
The code should look like this:
var watermark_action = actions.create("pdf-watermark");
watermark_action.parameters["inplace"] = true;
watermark_action.parameters["destination-folder"] = document.parent;
watermark_action.parameters["watermark-type"] = "text";
watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
watermark_action.parameters["watermark-font"] = "Helvetica";
watermark_action.parameters["watermark-size"] = "14";
watermark_action.parameters["page"] = "all";
watermark_action.parameters["watermark-depth"] = "over";
watermark_action.parameters["position"] = "center";
watermark_action.execute(document);
You were missing watermark-font, watermark-size, and page.

Clearing FlipTileData BackBackgroundImage

I have a periodic task that updates my live tile. Basically it looks like this:
var tileData = new FlipTileData()
{
BackgroundImage = mediumFrontUrl,
BackBackgroundImage = mediumBackUrl,
WideBackgroundImage = wideFrontUrl,
WideBackBackgroundImage = wideBackUrl
};
ShellTile primaryTile = ShellTile.ActiveTiles.First();
if (primaryTile != null)
{
primaryTile.Update(tileData);
}
There are certain occasions where I would like to not display the BackBackgroundImage and WideBackBackgroundImage. How do I clear the values? Simply setting things to null doesn't work (it just keeps what was there previously). According to the docs if I use XAML to create the live tile I can set Action="Clear". How do I set that in code?
You can clear the property for each Tile property.
For BackBackgroundImaga it's Empty URI:
BackBackgroundImage = new Uri("", UriKind.Relative)
More info on msdn page Tiles Overview for Windows Phone:
http://msdn.microsoft.com/en-us/library/hh202948%28v=vs.92%29.aspx
Hope this help
Best regards
And Zik
Just one trick.
Playing with WideBackContent and putting my own image (I have a lot of more possibilities with this apporach) I have problem with resetting WideBackContent. The thing that help me is not WideBackContent ="", then WideBackContent = " "
So, one empty space solved my problem.
Best regards

JSFL: selecting items returned by fl.findObjectInDocByType()

I can't seem to use the info returned by fl.findObjectInDocByType() with fl.getDocumentDOM().selection.
I want to use document.setTextRectangle to re-size some text fields from an array generated using fl.findObjectInDocByType().
I can easily access all the textObject properties but since document.setTextRectangle requires a current selection, I am at a loss.
The example in the documentaion for setting selection is:
fl.getDocumentDOM().selection = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0];
fl.findObjectInDocByType() returns an array of objects with the attributes: (object.timeline, object.layer, object.frame, object.parent)
But these are objects, and don't have a property for array index numbers required by fl.getDocumentDOM().selection=...
var doc = fl.getDocumentDOM();
var textFieldArray = fl.findObjectInDocByType("text", doc);
for (var i=0; i < textFieldArray.length; i ++){
fnResizeTheTextField(textFieldArray[i]);
}
function fnResizeTheTextField(theTextField){
//force current selection to be theTextField
//doc.selection MUST be an array, so assign theTextField to an array...
var selectArray = new Array();
selectArray[0] = theTextField.obj;
var theTimeline =theTextField.timeline;
var theLayer =theTextField.layer;
var theFrame =theTextField.frame;
doc.currentTimeline =theTextField.timeline;
doc.selection = doc.getTimeline().theLayer.theFrame.selectArray;//error
//resize the text rectangle
doc.setTextRectangle({left:0, top:0, right:1000, bottom:1000});
}
}
Result: Error:doc.getTimeline().theLayer has no properties
It turns out, the ObjectFindAndSelect.jsfl script already contains a function specifically for this: fl.selectElement(). Much more elegant:
var doc = fl.getDocumentDOM();
// generate an array of elements of type "text"
var textFieldArray = fl.findObjectInDocByType("text", doc);
for (var i=0; i < textFieldArray.length; i ++){
fnResizeTheTextField(textFieldArray[i]);
}
function fnResizeTheTextField(theTextField){
//force current selection to be theTextField
fl.selectElement(theTextField,false);//enter 'edit mode' =false...
//resize the text rectangle
doc.setTextRectangle({left:0, top:0, right:1000, bottom:1000});
}
}
I found the answer. In order to select anything for a document level operation, you have to also make flash focus on the keyframe of that object.
so, if I loop through an array of objects created by fl.findObjectInDocByType(), I use this code to make flash focus on the object correctly:
function fnMakeFlashLookAt(theObject){
doc.currentTimeline =theObject.timeline;
doc.getTimeline().currentLayer =theObject.layer;
doc.getTimeline().currentFrame =theObject.frame;
}
this may not work on objects nested inside a symbol however.
I had a similar issue recently, and apparently all google results about setTextRectangle() direct us here. It's unbelievable how poorly documented jsfl is :)
If you need to use setTextRectangle() inside an library item that is not on stage, you need to open for edit the item first.
Here's the code that solved my problem:
library.selectItem(libraryItemName);
doc.selection = [tf];//where tf is the reference to textfield we need to edit
doc.library.editItem(libraryItemName);
doc.setTextRectangle({left:l, top:t, right:r, bottom:b});
doc.selectNone();
If you have a better working solution, please post. I hope it saves somebody's time. Good luck!

Problems with adding/removing ContentPanes in AccordionContainer

I'm a complete newbie at Dojo, and Adobe AIR, which is my target. I'm
trying to put some panes into an AccordionContainer like so:
var mainview = dijit.byId("mainview");
var rand = randomString();
var widg = gtd_create_entry_widget(rand)
air.trace(mainview);
air.trace(widg);
mainview.addChild(widg);
"mainview" is my AccordionContainer, and gtd_create_entry_widget() is:
function gtd_create_entry_widget(id) {
var entry = new dijit.layout.ContentPane();
entry.attr("id",id);
entry.attr("title","title "+id);
return entry;
}
The pane shows up in the container, with the correct id and title, and
no errors, however, if I try to add another pane, the next one shows
up too, but I get the error:
TypeError: Result of expression '_7' [undefined] is not an object.
I get the same error if I run
var mainview = dijit.byId("mainview");
mainview.destroyDescendants();
and also, only one pane is destroyed at a time, and I understand this
method should destroy all the children.
I can include full project code if required.
Thanks a lot
Garry
I'm not exactly sure if this is going to fix your problem, but you're supposed to use dijit.layout.AccordianPane (http://www.dojotoolkit.org/api/dijit/layout/AccordionPane.html) with the AccordianContainer.