Showing posts with label Flash. Show all posts
Showing posts with label Flash. Show all posts

Sunday, July 7, 2013

BulkImageLoader Class: A class to load images in sequence.



Previously in one of the project, I have a requirement for loading images in bulk(more images a time). But the sequence that I am loading images will not keep the same when bitmaps are adding on stage. So to load images in sequence I have created bulkimageloader class with custom events. Now I can control the loading of images in as sequence.

Click here to download zip file.

In fla file,
bulkImageLoader=new BulkImageLoader(imgReqArr) //pass the array of image path to BulkImageLoader class.
bulkImageLoader.addEventListener(BulkImageLoaderEvent.ALL_LOAD_COMPLETE,AllImgLoaded);
 //when all images will be loaded, this event will fire.you will get “e.paramArr[0]” array which cantain all bitmaps.
bulkImageLoader.addEventListener(BulkImageLoaderEvent.SINGLE_LOAD_COMPLETE,SingleImgLoaded);
 //when any single image will be loaded , this event will fire. You will get “e.paramId” i.e. index of bitamp in array and “e.paramBit” bitmap of that image.

Download zip file. 

Hope this helps someone.
Enjoy ActionScript...

Saturday, July 6, 2013

Difference in accessing MovieClips on TimeLine and in ActionScript




I am always curious about how things happen. In flash I had a confusion as there is difference in accessing MovieClips on Timeline and accessing MovieClips in ActionScript. So somewhere on web I found this answer. I’ve just copy and pasted it here. Thanks to person “x” who explained this.


In Flash 9 when you create MovieClip instance on the Timeline and give it an instance name, you are doing two things:
  1. You're assigning the name property of the MovieClip instance to be the string equivalent to the instance name provided
  2. You're creating a variable in the current timeline with the name of the instance name that references that MovieClip instance

Flash does this behind the scenes when you publish your SWF to help you manage your movie clips on the screen. It's important to note that this behavior (specifically #2) is not seen with ActionScript. For Example:
Code:
// my_mc is the instance name of a movie clip
// created on this timeline
trace(my_mc); // [object MovieClip]
trace(my_mc.name); // my_mc

// create a new movie clip via AS
// add it to my_mc
var another_mc:MovieClip = new MovieClip();
another_mc.name = "child_mc";
my_mc.addChild(another_mc);

// instance name not available in parent timeline
trace(another_mc);  // [object MovieClip]
trace(my_mc.child_mc); // undefined
trace(my_mc.another_mc); // undefined
You can see that neither the instance name (name property) nor the variable to which the new MovieClip created with ActionScript was assigned is referencable through the movie clip in which it was added (my_mc). This is because another_mc was created and added to the timeline dynamically. Flash will only save instance names as variables for movie clips created on the timeline in Flash.

If you want to use an instance name to get a MovieClip (or any DisplayObject) instance from the timeline in which it exists, you can use getChildByName();
Code:
trace(my_mc.getChildByName("child_mc"));  // [object MovieClip]);
This will work for all movie clips despite where or how they were located as long as they are within the timeline/movie clip from which getChildByName was used.


Enjoy ActionScripting.................

Saturday, November 10, 2012

The MainTimeline and The Document class

 
In flash, Document Class represents the MainTimeline.
It means, the Variables or MovieClips or Functions defined on Timeline are also accessible in Document Class or vice versa.
And it also simply means, you cannot re-declare the Variables or MovieClips or Functions in Document Class, once you declare the same on Timeline. If you do so, you will get the error "1151: A conflict exists with definition [name] in namespace internal."

Let’s see how Timeline works:
The initialization of a SWF starts with the Document Class constructor function. The code written in constructor function of Document Class gets executed first, after that code written on Timeline frame1 will get executed.
If you don’t use Document Class to write code then flash internally create the one at the time of compiling swf and code written in each frame will get converted to frame number function in Document Class. Ex. If you write code on frame number 1, flash will create the function named frame0 and put all code within this function. This is the flow of execution for all frames and the code on particular function get executed when play head reaches to that frame. Remember one thing here, though Timeline starts with frame1, flash considers this as index 0. so frame1 code will be declared in function named "frame0" and so on.

The Variables and Functions declared on Timeline are accessible throughout the fla and Document Class, as they are considered as internal access specifires. MovieClips, Buttons declared on Timeline have limited scope in particular function, as they exists till the Playhead is present on that frame on timeline. Document Class is always considered and declared as public to access the things in all project.

If you are not using Document Class then also this execution is same for Document Class created by flash at compile time and in constructor function of it using addFrameScript method, which is undocumented feature of flash.

Since frame0, frame1 etc. are the function names that flash uses internally, we cannot use the same named functions. In such situation flash gives error: "1023: Incompatible override."/"1021: Duplicate function definition."
However you can use the same function name except in the same frame. ie. function frame10() will give above arror if it is written on frame10, but you can write the function frame10() on any other frames.
For Document Class you have to extends class as MovieClip or Sprite. but if you have a code on timeline you have to extend the class as MovieClip, extending sprite will give you error as Sprite does not have timeline. 
For more details, create your own swf file having code on timeline and decompile it using Sothink SWF decompiler. In ‘actions’ folder, in ‘resources’ panel you will get the flash compiled code.

Also to clear the difference between MainTimeline, Root and Stage check the following outputs on Timeline and Document Class sepretaly.

trace("this " + this);
trace("root " + root);
trace("root.parent " + root.parent);
trace("stage " + stage);
trace("parent " + parent);

Sunday, June 24, 2012

Useful tool: Size report



What you will learn
• How to generate size report of flash movie.
• How to check size of each object, on each frame.


Hello readers,

After a couple of months, i came here with couple of articles.
Here we will see, how to generate size report of flash movie.
Size report is one of the important feature of Adobe Flash. As Your flash movie contain lot of objects, sound, movieclips, bitmaps, graphics, embedded text, actionscript code. Each object allocates its size in swf file. By generating size report, you will get detailed information about size of each object used in fla. Size Reports allow you to troubleshoot and find the elements in your swf movie that causes an increase in the overall file size. Which could be help you to optimize flash file size.

How to publish size report
To publish a Size Report
  1. Go to File > Publish Settings.
  2. Click on the Flash Tab.
  3. In the Flash tab go to Advance section and select Generate Size Report.
  4. Click on Publish to generate a size report Or Click OK to get out of the Publish Setting Dialog.
  5. Come to your folder where Fla files are being saved and locate the size report document “Fla file name”+ Report.txt.
  6. Open the size report by double clicking.
  7. After compiling flash movie, you will notice the size report is being generated in output panel.
Figure 1. Size Report in Publish Settings.



The report contain following sections,
  • Frame: This explains how much size each frame contains.
  • Scene: This explains how much size each object contains in that scene.
  • Symbol: This section explains file size of all the MovieClips, Buttons and Graphic Symbols in file. This section also lists any components that used in file.
  • Font: This section lists embedded fonts and their glyphs used in the file. You will get size of font, name of the embedded font and the characters in that font that are available.
  • ActionScript: This section shows the size in bytes of any actionScript in file.
  • Bitmap: This is a very useful section to check if you are embedding any bitmaps in file. Here you will get the name of bitmap in library panel. Original file size, Compressed file size and Compression ratio of JPEG Quality.
Hope this will help you to enjoy Flash and ActionScripting.