cancel
 

 

Job type :

Zip Code :

community forums

Featuring over 100 topics of interest to DoItYourselfers.

How to Organize Visual Content with ActionScript

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Video Transcript

We do not need this file open anymore so let us close that down. So we close and open up a new project file which is going to be scavengerhunt_4_raw. Let us save that straight away. That is scavengerhunt_4. You can see that our Join Movie Clip is still actually represented on the stage. What we are going to do now is actually attach that movie clip from the Library by our action script at runtime. So we can just delete the join line now from that timeline and let us select the first action script frame.

Go to our Actions Panel and we are going to scroll down to underneath the Comment Block that starts with update the visibility of the all view. So we are going to add in their function update view. We are going to declare this a function first, give it its name. It does not have any argument so we are just going to have open and close bracket and a return type of void. This is a function we are going to call to dynamically attach the join movie on to the stage at runtime. In order for us to be able to access the join movie clip from the Library at runtime, there are something special we need to do. If we go and right mouse click on the join movie clip in the Library, you can see an option called Linkage. This dialog box gives us some options for working with this movie clip at runtime. So, let us choose the check box Export for Action Script and we get the ability to be out of put and identify for this movie clip.

By default, it uses the movie clips 9 from the Library so we are just going to leave this as join for the time being. Everything else in this dialog box is good. So let us click okay and go back to our Actions Panel. Now, inside the update view function, we are going to write the action script that attaches the movie to the stage. The action script that uses the code for the task is called Attach Movie. The first attribute of the attach movie function that we are using needs to be id name. This is the name of the identifier of the movie clip that we want to attach and in this case, it is Join. The second attribute is the name that will be given to the newly created movie clip that gets attached to the stage. This is going to be join_mc. The third attribute of attach movie has to do with depth. Let us just type this for the moment and I will explain the concept of movie clip depth a little bit more.

The depth for the movie clip is an integer from -16,383 although I have the positive 16,383 and this represents a stoking order. It is positioned along the said access of the parent movie clip. Only one visual object maybe present at any given depth. Depth values are saw in automatically at design time by the Flash Lite authoring tool. Values are assigned based on the relative order of the layer on which visual objects are placed. So, individual objects depth may also be controlled using tools on the Modify Arrange Menu. Objects with the higher value appear acquainted to the DI and objects with the lower value appear behind other objects if they are covered. So, the movie clip object exposes three methods that are related to depth, get next highest depth, get depth and swap depths. This is just a way for us to manage the socking order of movie clips when we are attaching them to the stage runtime so that we can mimic the way that the layers work out on the main timeline.

Now, let us scroll down in the Actions Panel a little bit further and underneath the comment that says Set the Initial State, we are going to invoke the Update View Function. Let us save this and test it. Great! So even though we removed from the stage at join movie clip of that join layer, now you can see that when we call the update view function, it is attaching the join movie clip from the Library and placing on the stage for us. The only problem is that is not exactly where we want it. So, let us go back to our Actions Panel. What we need to do is set some default values for the join movie clip when it gets added to the stage. There are a couple of ways that we can do this. The first way is using what we call an init object. It is just an object that we create in action script and give some default values to. So, when we use attach movie, we can also tell it to use all the values from init object. So, it would look something like this. Let us go back up above the update view function, add in some space. Let us create a new object called init. We are going to data type it as an object and say that is new object. It is a new type of this class. Now, we will assign some default values. Let us use the X and the Y so that we can position this join form properly on the stage. We can change the properties directly on to this object. So our object could read init and then the property name ._x and let us set it to 15. We will do the same for Y and set that to 90.

Now, in our attach movie action script, we need to add a fourth parameter which is this init object. So, we go back to our attach movie action script and after get next highest depth, we add in another attribute. We would simply use init, the name of the object that we had created. Let us save this and test our movie not and see what happens. Great! So it has inherited the X and Y values of the init object so that when we attach it to the stage, it already knew where it had to go. Let us go back to our Actions Panel and look a slightly different way of getting the same job done. Rather than having to create a separate init object every time we use attach movie, we can put this default values into the attach movie action script itself. So let us go back and delete that init object that we created and where we have init in the action script, let us change it to what we call an object literal. If we put curly braces here, this says to the action script that whatever we place inside here are the default values for an object so it is just replacing the three lines of code that we just removed.

We still want to use the X and Y position as our default values so what we would type would simply be the properties and their values. Because it is an object literal, we use a slightly different syntax when setting the properties for X and Y. Now, let us run this and we should see exactly the same thing. There we go! Rather than inheriting the properties of the init object, we have now got it just using the object literal past straight into the action script that we used for attach movie.
We do not need this file open anymore so let us close that down. So we close and open up a new project file which is going to be scavengerhunt_4_raw. Let us save that straight away. That is scavengerhunt_4. You can see that our Join Movie Clip is still actually... click to read more


Painting Stylish Wall Borders

sponsored articles of the day

diy centers

Research and explore a wealth of wisdom on these topics