FLASH MX 2004: Flat Bedding pattern

Source: Internet
Author: User
Tags one more line
This translator: Egoldy
Article Nature: Original
Article Source: http://www.webstudio.com.cn/tutorial/show.php?id=30

FLASHMX2004 as Tile background


For Web site designer to often use a tiled background, in general, we used the method in PS first tile the background, and then save into a map, import into the Flash, this way is possible, but the disadvantages are two, one is the size of the file will be relatively large, another problem is when you want to change the size of the file, Background image to be done again in PS, in the import. Now we're going to look at how to use ActionScript to tile the background.
Demonstrate:

We need to use the material, we only need to tile like in PS, a small piece of shading material. The following figure

If you want more images like shading you can search the Web, or go here to pattern

1. First create a new animation file, set wide to 400, high to 300, of course this is the size of this example, you can also set the size you want.

2. Now all you have to do is import our selected shading map into the FLASHMX2004 scene, select File Import, and select a small texture picture.

3. When you import a picture, if you import it directly into the scene, select the small and medium graph, press F8, and convert the picture to a movie clip. Name the movie clip name tile, as shown in figure:

4. Do not close the dialog box at this time, click on the Advanced tab, select in for the action script export, in the ID input we need in the program ID name, here we enter Timage, as shown in the following figure.

5. Still select the image symbol just converted to, open the property panel to see its wide and high values, in this case the image width is 26, height is 26.    Be aware of this size and note that it's in the back as needed to use it. 6. In addition to the image symbol in the scene, do not frost because it has been saved in the library, and we have set the ID number for it. Set the link ID is for the back we want to use the Attachmovie method and paste it.
7. Select the first frame in the scene, press F9, open the Action panel, and paste the following code on the first frame OK. As follows:

Code:

















To test the film, you will see the following results: Film 1.swf

We found that the background has been tiled, but we found a small problem is on the right side of a place is not paved, this is not urgent, we first look at the code. And then we're going to look at why.

Code:

            

To define a function, the function name is TILEBG, and note that this function has no parameters.

Code:

            
Above the initial size of our texture map, we currently use the image length is 26.

Code:

            

Using the width and height of the stage divided by the height of the texture map to calculate how much the horizontal and vertical direction can be paved, the Math.Round function used here. To take an approximate value.

Code:





}
These two cycles are for the formation of our tiled grids, such as when the x=0, Y to pave a column, when X=1, y in the secondary row. Until the end of the shop.

Code:

To make our image groups strong to the scene, use the Attachmovie method to view the help document.

Code:


Finally, set the coordinate position of the image.

* In the example above we have a problem, is to find a white side of the right there is not paved, in general, if your shading picture is a square, and the size of the film is also a square will not appear this problem, but the current we use the size of the 400*300, we found that in fact is less than a column, We can take the horizontal and vertical columns as long as we have one more line. Modify the following code:

Change the Math.Round to Math.ceil to take a larger value. This will be one more line and the problem will be solved.

Code:


Take a look at the results! :)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.