por Jonas Galvez
Interessante: cole o seguinte script no Flash MX e depois execute.
new Function(this.onResize = function() {
this.clear();
this.lineStyle(3, 0);
this.moveTo(10, 10);
this.lineTo(Stage.width-10, 10);
this.lineTo(Stage.width-10, Stage.height-10);
this.lineTo(10, Stage.height-10);
this.lineTo(10, 10);
}).call(this);
Stage.addListener(this);
Stage.align = "TL";
Estou fazendo alguns experimentos com o evento onResize. Ele pode ser um recurso muito útil em alguns casos. Quem quiser saber mais, veja no dicionário do ActionScript os items "onResize" e "align" (objeto Stage)
--------------------------------------------------------------------------------
Opa... acho que há algo errado aqui:
}).call(this);
Não há nada errado no script, a chave se refere ao conteúdo do objeto e o parêntese à nova função.
Funciona sem problemas.
Na verdade o Jonas poupou a escrita no código atribuindo o ".call(this)" sequenciando o objeto criado, faça o teste:
Retire o ".call(this)" da linha, dê um enter e coloque:
this.onResize.call(this);
Aliás, não há a necessidade do "this" para este caso:
this.onResize.call();
ou
}).call();
--------------------------------------------------------------------------------
Você está enganado.
O "call(this)" é realmente necessário, Dauton. Na verdade, o "call()" também executará a função, mas o "this", dentro da função, não estará apontando para a timeline na qual a função foi executada. Veja o seguinte exemplo:
this.simpleTest = function() {
trace(typeof this);
};
Teste com o seguinte código:
// object - aparentemente, um objeto vazio é passado
this.simpleTest.call();
// movieclip - agora sim, o resultado esperado
this.simpleTest.call(this);
new Function(this.onResize = function() {
this.clear();
this.lineStyle(3, 0);
this.moveTo(10, 10);
this.lineTo(Stage.width-10, 10);
this.lineTo(Stage.width-10, Stage.height-10);
this.lineTo(10, Stage.height-10);
this.lineTo(10, 10);
}).call();
// Stage.addListener(this);
Stage.align = "TL";
Note que a linha que faz com que a linha de tempo se torna listener do objeto Stage (Stage.addListener) não será executada. Nada aparecerá no SWF. Se você testar sem o (//) antes do Stage.addListener, o desenho só aparecerá porque o evento onResize foi chamado logo após a execução (o stage do Flash foi provavelmente redimensionado no Flash Player do Flash MX). Se você testar da seguinte forma:
new Function(this.onResize = function() {
this.clear();
this.lineStyle(3, 0);
this.moveTo(10, 10);
this.lineTo(Stage.width-10, 10);
this.lineTo(Stage.width-10, Stage.height-10);
this.lineTo(10, Stage.height-10);
this.lineTo(10, 10);
}).call(this);
// Stage.addListener(this);
Stage.align = "TL";
Agora sim, o desenho aparecerá
Jonas Galvez
|
|