Doubt with Actionscript3 Classes and Objects

Asked

Viewed 229 times

2

Description of the Project

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

Load list displaying 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:

  • 1° Layer (background): background image;
  • 2° Layer (buttons): side rectangle with one button for each item ;
  • 3°Layer (mascara_botoes_items): mask so that only the buttons in the center of the lateral rectangle appear;
  • 4° Layer (up_down): buttons to lower and raise item buttons;
  • 5° Layer (stage): presents the image of the large item and its description below;

Doubts

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

If possible, it would also help to know only the Classes I must know for this job.

1 answer

2


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

Now, to turn an image into a "clickable" object you can load it into an object MovieClip and change property buttonMode for true. The Actionscript is event orientation, as well as Javascript, for you listen to mouse click you use the method addEventListener. To apply mask to them, just change the parameter mask for 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 stage, you can use only one Movieclip and a single Textfield, changing the information contained within them. It is the best practice regarding creating frames, since each frame will contain a different object and consequently the level of processing/memory of the application. Even you can create a method for this, I believe something like 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;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.