load a movie clip from library into the stage using AS 2 - movie

how can i load a movie clip using AS2 from library into my stage. and how to unload it. could u help me ? i appreciate it

In the library, you must to assign a Linkage (right click on th mc) and chech Export for Actionscript and set a name (for example myMovieClip). That name will be used by attachMovie method:
this.attachMovie('myMovieClip', 'myMovieClipNewName', depth);
and for remove;
this.removeMovieClip('myMovieClipNewName');
chaus

depth = 1;
while(depth<100){
this.attachMovie('bullet','bullet' + depth,depth);
this["bullet" + depth]._x = random(550);
this["bullet" + depth]._y = random(400);
depth++;}
//to create 100 bullets randomly on the screen

Related

ImageJ/Fiji - Save CSV using macro

I am not a coder but trying to turn ThunderSTORM's batch process into an automated one where I have a single input folder and a single output folder.
input_directory = newArray("C:\\Users\\me\\Desktop\\Images");
output_directory = ("C:\\Users\\me\\Desktop\\Results");
for(i = 0; i < input_directory.length; i++) {
open(input_directory[i]);
originalName = getTitle();
originalNameWithoutExt = replace( originalName , ".tif" , "" );
fileName = originalNameWithoutExt;
run("Run analysis", "filter=[Wavelet filter (B-Spline)] scale=2.0 order=3 detector "+
"detector=[Local maximum] connectivity=8-neighbourhood threshold=std(Wave.F1) "+
"estimator=[PSF: Integrated Gaussian] sigma=1.6 method=[Weighted Least squares] fitradius=3 mfaenabled=false "+
"renderer=[Averaged shifted histograms] magnification=5.0 colorizez=true shifts=2 "+
"repaint=50 threed=false");
saveAs(fileName+"_Results", output_directory);
}
This probably looks like a huge mess but the original batch file used arrays and I can't figure out what that is. Taking it out brakes it so I left it in. The main issues I have revolve around the saveAs part not working.
Using run("Export Results") works but I need to manually pick a location and file name. I tried to set this up to take the file name and rename it to the generic image name so it can save a CSV using that name.
Any help pointing out why I'm a moron? I would also love to only open one file at a time (this opens them all) and close it when the analysis is complete. But I will settle for that happening on a different day if I can just manage to save the damn CSV automatically.
For the most part, I broke the code a whole bunch of times but it's in a working condition like this.
I appreciate any and all help. Thank you!

Error in batch merging images (x.tif is not a valid choice for "C2 (green):")

I want to merge two sets of fluorescence microscope images into a green & blue image, but I'm having trouble with the macro (haven't used ImageJ before). I have a folder of FITC-images to be coloured green and a folder of DAPI-images to be coloured blue. I have been using this modified version of a macro I found online:
macro "batch_merge_channel"{
count = 1;
setBatchMode(true);
file1= getDirectory("Choose a Directory");
list1= getFileList(file1);
n1=lengthOf(list1);
file2= getDirectory("Choose a Directory");
list2= getFileList(file2);
n2=lengthOf(list2);
open(file1+list1[1]);
open(file2+list2[1]);
small = n1;
if(small<n2)
small = n2;
for(i=0;i<small;i++)
{
run("Merge Channels...", "c2="+list1[1]+ " c3="+list2[1]+ " keep");
name = substring(list1, 0, 13)+")_merge";
saveAs("tiff", "C:\\Merge\\"+name);
first += 2;
close();
setBatchMode(false);
}
This, however returns an error
x.tif is not a valid choice for "C2 (green):"
with x being the name of the first file in the first folder.
If I merge the images manually, two by two, there is no error. So I'm presuming the problem is in the macro code.
I found several cases of this error online, but none of the solutions that seemed to work for those people work for me.
Any help would be appreciated!
In case you didn't solve this already, a great place to get help on ImageJ questions is the forum.
I can suggest a couple of ideas:
Is your image successfully opened by the macro? You could set the batch mode to false to check this.
It looks to me like the for loop does not employ the variable i. It works on the first pair of
images (list1[1], list2[1]), then closes the merged image, but then
tries to process image 1 again. To actually loop through all the
images in the folder, you have to put inside the loop something
like this (you don't need 'keep' -- better to leave it out so the source images will automatically be closed)
open(file1+list1[i]);
open(file2+list2[i]);
run("Merge Channels...", "c2="+list1[i]+ " c3="+list2[i]);
-- Turning off batch mode should be done after the loop, not within the loop.
Here's a version that works for me.
// #File(label = "Green images", style = "directory") file1
// #File(label = "Blue images", style = "directory") file2
// #File(label = "Output directory", style = "directory") output
// Do not delete or move the top 3 lines! They contain essential parameters
setBatchMode(true);
list1= getFileList(file1);
n1=lengthOf(list1);
print("n1 = ",n1);
list2= getFileList(file2);
n2=lengthOf(list2);
small = n1;
if(small<n2)
small = n2;
for(i=0;i<small;i++)
{
image1=list1[i];
image2=list2[i];
open(file1+File.separator+list1[i]);
open(file2+File.separator+list2[i]);
print("processing image",i);
run("Merge Channels...", "c2=&image1 c3=&image2");
name = substring(image1, 0, 13)+"_merge";
saveAs("tiff", output+File.separator+name);
close();
}
setBatchMode(false);
Hope this helps.

Actionscript 3: Call to undefined method

I am brand new to Actionscript and this is one of my first "scripts" by myself so forgive me if this is obvious.
I have a movieclip with the name "Smiley"
and this is my actionscript in frame 1 of the actions layer
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousePosition);
var smiley:MovieClip = addChild(new Smiley) as MovieClip; // **ERROR HERE**
stage.addEventListener(MouseEvent.MOUSE_DOWN,toggleSmiley);
stage.addEventListener(MouseEvent.MOUSE_UP,toggleSmiley);
function mousePosition(event:MouseEvent) {
smiley.x = mouseX; smiley.y = mouseY;
}
function toggleSmiley(e:MouseEvent):void
{
smiley.visible = (e.type == MouseEvent.MOUSE_DOWN);
}
See the line marked "ERROR HERE" above, thats where Flash is throwing the error.
I am getting this error:
Scene 1, Layer 'actions', Frame 1, Line 6 1180: Call to a possibly
undefined method Smiley.
Am confused as to where the problem is. Thanks in advance.
Your "Smiley" has not been linked for usage with ActionScript. It doesn't exist, as far as your script knows.
In the library, in "Smiley"'s Symbol Properties, check "Export for ActionScript".
In your library, you'll need to export your Smiley for Actionscript. Open up your library, select the square, and select the "properties" by right-clicking or cmd+clicking. Twirl down the "Advanced" section if it's not open already, then select "Export for Actionscript". In the "Class" field you should likely see the same name as it is in the library, "Smiley". This creates its own class which has the properties of the movie clip you designed in Flash.
Below this field, you'll see "Base Class", and it should have "flash.display.MovieClip". This means that your Smiley is already a movieclip, and it is just extended to be an extra special type now called Smiley, so you won't have to declare it as a MovieClip in your code when you instantiate it, because a Smiley is already a MovieClip.
Now go back to your actions, and you'll change the line you instantiate it with to:
var smiley:Smiley = new Smiley();
addChild(smiley);
In general, you want to call the constructor of a class first, ie: "new Smiley()", and then add it to the display list, rather than trying to do it all at once.

pixFRET - running the plugin for time lapse images // looping?

I just recently started to work with ImageJ (and thus do not have much experience with macro programming) to analyze my microscopy pictures.
In order to generate FRET pixel-by-pixel images that are corrected for spectral bleed through I am using the plug in: pixFRET. This plug in requires a stack of 3 images to work: FRET, Donor, Acceptor. So far, I have to open every picture myself and this is REALLY inconvenient for large time stacks (> 1000 images). I am looking for a way to loop the plug in or create some kind of macro to do this.
A short description of my Data structure:
workfolder\filename_t001c1 (Channel 1 Image - Donor at time point 001),
filename_t001c2 (Channel 2 Image - FRET at time point 001),
...t001c3 (can be neglected)
...t001c4 (Channel 4 Image - Acceptor at time point 001).
I would have to create a stack of C2/C1/C4 at each time point that is automatically analyzed by pixFRET (with set parameters) and the result should be saved in an output folder.
I am grateful for every suggestion as my biggest problem is the looping of this whole stack generation/pixFRET analysis (can only do this manual right now).
Thanks
David
I did not find a way to directly include the parameters and commands from the pixFRET PlugIn. However, here I show a work around that works with IJ_Robot to add these commands. I further included some stuff to perform a alignment of the camera channels based on the first images of the time series.
// Macro for creating time resolved pixFRET images with a alignment of both cameras used
// a separate setting file is required for pixFRET -> put this into the same folder as the pixFRET plugin
// the background region has to be set manually in this macro
// IJ_robot uses cursor movements - DO NOT move the cursor while excuting the macro + adjust IJ_robot coordinates when changing the resolution/system.
dir = getDirectory("Select Directory");
list = getFileList(dir);
//single alignment
run("Image Sequence...", "open=[dir] number=2 starting=1 increment=1 scale=100 file=[] or=[] sort");
rename(File.getName(dir));
WindowTitle=getTitle()
rename(WindowTitle+toString(" Main"))
MainWindow=getTitle()
NSlices=getSliceNumber()
xValue=getWidth()/2
yValue=getHeight()/2
//setTool("rectangle");
makeRectangle(0, 0, xValue, yValue);
run("Align slices in stack...", "method=5 windowsizex="+toString(xValue*2-20)+" windowsizey="+toString(yValue*2-20)+" x0=10 y0=10 swindow=0 ref.slice=1 show=true");
selectWindow("Results");
XShift=getResult("dX", 0);
YShift=getResult("dY", 0);
File.makeDirectory(toString(File.getParent(dir))+toString("\\")+"test"+" FRET");
for(i=0;i<list.length;i+=4){
open(dir+list[i+1]);
run("Translate...", "x=XShift y=YShift interpolation=None stack");
open(dir+list[i]);
open(dir+list[i+3]);
run("Translate...", "x=XShift y=YShift interpolation=None stack");
wait(1000);
run("Images to Stack", "name=Stack title=[] use");
selectWindow("Stack");
makeRectangle(15, 147, 82, 75); //background region
run("PixFRET...");
run("IJ Robot", "order=Left_Click x_point=886 y_point=321 delay=500 keypress=[]");
run("IJ Robot", "order=Left_Click x_point=874 y_point=557 delay=500 keypress=[]");
selectWindow("NFRET (x100) of Stack");
save(toString(File.getParent(dir))+toString("\\")+"test"+" FRET"+toString(i) +".tif");
selectWindow("Stack");
close();
selectWindow("FRET of Stack");
close();
selectWindow("NFRET (x100) of Stack");
close();
run("IJ Robot", "order=Left_Click x_point=941 y_point=57 delay=300 keypress=[]");
}
Thanks for your help Jan. If you can think of a way to call these pixFRET commands directly rather than using Ij_robot, please let me know.
Take this tutorial from Fiji (is just ImageJ) as a starting point, and use the macro recorder (Plugins > Macros > Record...) to get the neccessary commands.
Your macro code could then look something like this:
function pixfret(path, commonfilename) {
open(path + commonfilename + "c2");
open(path + commonfilename + "c1");
open(path + commonfilename + "c4");
run("Images to Stack", "name=Stack title=[] use");
run("PixFRET"); // please adjust this to your needs
}
setBatchMode(true);
n_timepoints = 999;
dir = "/path/to/your/images/";
for (i = 0; i < n_timepoints; i++)
pixfret(dir, "filename_t" + IJ.pad(i, 4));
setBatchMode(false);
Hope that helps.

Image list usage

I store the icons for my applications inside several image lists.
Have one to:
X16
X24
X48
X32
Both TActions and direct access to place ICOs in a TButton, or TImage came from this several Image Lists.
My problem is that when I need to remove one its nightmare
I thought of setting a CONST value to everyone, but as some are used in TActions it’s not a complete solution.
How are you guys doing this and what solutions do you have to solve or at least improve this?
I use DELPHI 2007.
What I do is add all the icons at runtime by loading from then from resources. When I add them I save the index of the added icon to a global variable. I also assign the ImageIndex property of each action at runtime by referring to these global variables.
This allows flexibility to add and remove icons to the project without having numbering problems. The approach caters for runtime icon size decisions based on font scaling. The drawback is that you don't get to see the images at design time which is a drawback. If you want to have all the flexibility outlined above I don't see a better solution. In an ideal world the images would be identified by a name or an ID rather than a contiguous index into an array. But to achieve that you would need to implement a lot of code on top of the VCL.
There are several solutions to this problem.
If you want to use constants, but you don´t want to change them all each time you remove an image. You can do the following:
const
idImgA = 0;
idImgB = idImgA + 1;
idImgC = idImgB + 1;
idImgD = idImgC + 1;
idImgE = idImgD + 1;
idImgF = idImgE + 1;
idImgG = idImgF + 1;
When you want to remove image D, you only need to change two lines:
const
idImgA = 0;
idImgB = idImgA + 1;
idImgC = idImgB + 1;
idImgE = idImgC + 1;
idImgF = idImgE + 1;
idImgG = idImgF + 1;
Another way is to work with enum types:
type
TImgEnum = (imgA, imgB, imgC, imgD, imgE, imgG);
You can use the Ord operator to get the image index:
index := Ord(Enum);

Resources