Doubts with ActionScript Classes and Objects

2

Description of the Project

I'm developing a slide catalog, in which there are photos and texts, which are loaded dynamically from urls provided in a list.

Load list that has this format:

nome_do_item url_da_sua_imagem url_da_sua_descrição

Example:

produtoA http://www.empresa.com.br/img/produtoA.png http://www.empresa.com.br/desc/produtoA.txt

The flash image consists of the following:

  • 1st layer (background): background image;
  • 2nd layer (buttons_items): one-button side rectangle for each item;
  • 3rd layer (mascara_botoes_items): mask so that only the buttons in the center of the side rectangle appear;
  • 4th layer (up_down): buttons to go down and up the item buttons;
  • 5th Layer (stage): displays the image of the large item and its description just below;

Questions

  • For each time you pull the urls files and need to clean the library?
  • How to dynamically create buttons with the Items image, and insert them into a rectangle, which serves as a container, so that you can move only the rectangle and not all the buttons?
  • When clicking on an item button, to change the image and the description of the stage using ActionScript, should I create a frame for each item ?, or just select a rectangle and a TextField as a stage and change its value? li>

If possible, it would also help to know only the Classes that I should be aware of for this work.

    
asked by anonymous 23.07.2014 / 14:23

1 answer

2

A VM of ActionScript (Flash Player) has a Garbage Collector , which runs, indefinitely, to remove objects that are not being used by your project. (This link can help you .

Now to transform an image into a clickable object you can load it into a MovieClip object and change the buttonMode property to true . ActionScript is event orientation , just like JavaScript, for you listen the mouse click you use the addEventListener method. To apply mask to them, just change the mask parameter to the MC mask. See the example:

var botaoMC:MovieClip = new MovieClip();
botaoMC.buttonMode = true;
botaoMC.mask = mascaraMC;
botaoMC.addEventListener(MouseEvent.CLICK, clicouMouse);

function clicouMouse(e:MouseEvent):void {
    trace("Clicou com mouse sobre o MovieClip");
}

To display the items on the Stage, you can use only a MovieClip and a unique TextField, by changing the information contained within them. It is best practice to create frames, since each frame will contain a different object and consequently the application's processing level / memory. Even you can create a method for this, I believe something like this below:

function alterarSlide(img:Bitmap, str:String):void {
     for(var i:int = 0; i < imagemMC.numChildren; i++) {
         imagemMC.removeChildAt(i);
     }
     imagemMC.addChild(img);
     //img.width - Largura
     //img.height - Altura
     texto_txt.text = str;
}
    
24.07.2014 / 15:33