Lesson : Window Component
In this tutorial, I will teach you how to use Window component. In window component you can load MovieClips or even another SWF files.
Flash 8, AS 2.0
Output:
Download Source Files
Step 1: Open new Flash Document.
Step 2: Open components panel (Ctrl + F7) or Windows -> Components.
Step 3: In components panel under User Interface, you can find Window component.
Step 4: Click and drag the window component on to your stage.
Step 5: Left click on the window component and open the properties panel (Ctrl + F3) and give "win" as instance name.
Step 6: Now create a simple Movieclip with some little animation in it.
Step 7: Open the Library (Ctrl + L), right click on the Movieclip and select Linkage.
Step 8: In Linkage Properties window, check Export for ActionScript. Give "ani" as identifier.
Step 9: This Movieclip will be our content of our window.
Step 10: Now click the first frame and open the Actions panel (F9), and paste the below code in it.
win.title = "Sample Window";
win.closeButton = true;
win.contentPath = "ani";
win.setSize(250,200);
var listener:Object = new Object();
listener.click = function(){
win._visible = false;
}
win.addEventListener("click",listener);
Code Explanation:
win.title = "Sample Window";
You can assign title to your Window component.
win.closeButton = true;
By default the close button on the right top corner is false, to enable the close button we must initialize it to "true".
win.contentPath = "ani";
It is used to place the content inside the window component, where "ani" is a movieclip.
win.setSize(250,200);
It is used to set the width and height of the window component. The first parameter is width and second one is height. The height parameter also includes the height of the title bar which is 25px, so we must always add 25px to our height.
var listener:Object = new Object();
listener.click = function(){
win._visible = false;
}
win.addEventListener("click",listener);
In here we are adding Event Listener to the close button, when the user clicks on the close button the window visibility is switched to false.
- End of Tutorial!