I am currently experimenting with a very simple graphical interface ... "engine" (I think you could call it). Its essence:
- There is a FrontController that falls under user requests; every request has a uid
- each uid (read "page") has an announcement about the components ("modules") that are present on it
- are subclasses of Sprite and, in fact, are unique
Naturally, I need a way to hide / show these sprites. For the time being, it seems to me pretty much what Flex has by default - in the sense that "if we are in the place where comp is displayed, create it, cache it and reuse it every time it is displayed again "
The question is what would be a more appropriate and effective way of hiding and displaying - through addChild/ removeChildor switching visible.
As I see it:
visible is fast and dirty (during the first tests)visibledoes not create a chain of bubble events like Event.ADDEDorEvent.REMOVED- Invisible components do not receive mouse events.
So, it removeChildwill be what I would call when I'm sure that the component will no longer be needed on the screen (or the cache is too big, for example)
stackoverflow'ers/AS3-crazed?
:
( google).
i visible; , -, ; " FLASH PLATFORM" Adobe . 69 .
, , :
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.utils.getTimer;
public class DisplayBM{
public function DisplayBM(stage:Stage){
super();
var insts:uint = 5000;
var v:Vector.<Sprite> = new Vector.<Sprite>(insts);
var i:Number = v.length, s:Sprite
while (i--){
s = new Sprite;
s.graphics.beginFill(Math.random() * 0xFFFFFF);
s.graphics.drawRect(
Math.random() * stage.stageWidth,
Math.random() * stage.stageHeight,
10,
10
);
s.graphics.endFill();
v[i] = s;
}
var store:Object = {};
store[Event.ADDED] = null;
store[Event.REMOVED] = null;
var count:Function = function(e:Event):void{
store[e.type]++;
}
var keydown:Function = function (e:KeyboardEvent):void{
var key:String
for (key in store){
store[key] = 0;
}
stage.addEventListener(Event.ADDED, count);
stage.addEventListener(Event.REMOVED, count);
var s0:uint = getTimer(), op:String;
var i:Number = v.length;
if (e.keyCode === Keyboard.NUMBER_1){
op = 'addChild';
while (i--){
stage.addChild(v[i]);
}
}
if (e.keyCode === Keyboard.Q){
op = 'removeChild';
while (i--){
stage.removeChild(v[i]);
}
}
if (e.keyCode === Keyboard.NUMBER_2){
op = 'visibile';
while (i--){
v[i].visible = true;
}
}
if (e.keyCode === Keyboard.W){
op = 'invisibile';
while (i--){
v[i].visible = false;
}
}
if (op){
var events:Array = [];
for (key in store){
events.push(key + ' : ' + store[key])
}
trace(op + ' took ' + (getTimer() - s0) + ' ' + events.join(','));
}
stage.removeEventListener(Event.ADDED, count);
stage.removeEventListener(Event.REMOVED, count);
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown);
}
}
}