linoart 0 Denunciar post Postado Março 30, 2009 to tentando carrgar um arquivo swf. nele contem um arquivo .as que uso pra fazer as posições e resizes dos moviesclips. depois que todo o carregamento é concluido ele acusa esse erro: TypeError: Error #1009: Cannot access a property or method of a null object reference. at cirurgia_resizeAnima$iinit() nao sei se tem algo a ver, mas o arquivo que carregará tambem usa um arquivo .as, que também uso para posições e resize. é um arquivo .fla e um arquivo .as pro swf que ira carregar, e um .fla e um .as pro arquivo a ser carregado. esse é o arquivo .as do swf que vai ser carregado (eu copiei ele do arquivo que carregará e apenas mudei o nome e posições dos movieclips ): package { import flash.display.StageScaleMode; import flash.events.Event; import flash.display.MovieClip; import flash.display.*; import flash.events.ProgressEvent; import flash.events.*; import flash.net.URLRequest; import flash.events.MouseEvent; import flash.display.* import flash.events.TimerEvent; import flash.utils.Timer; import flash.text.*; import caurina.transitions.Tweener; import flash.display.StageScaleMode; import flash.display.StageAlign; import flash.display.Stage; public class cirurgia_resizeAnima extends MovieClip { private var tamStageW; private var tamStageH; public function cirurgia_resizeAnima() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = "TL"; stage.addEventListener(Event.RESIZE, onResize); tamStageW=stage.stageWidth; tamStageH=stage.stageHeight; logotipo.x = 50; menu_principal.x = 70; topo.width = tamStageW; ////////////////////////////////////////// THUMBS thumb1.x = tamStageW / 2 thumb1.y = topo.y + topo.height + 60; thumb2.x = thumb1.x + thumb1.width + 10; thumb2.y = thumb1.y thumb3.x = thumb2.x + thumb2.width + 10; thumb3.y = thumb1.y mulher.y = topo.y + topo.height + 130 mulher.width = tamStageW; slogan.x = tamStageW /2 - slogan.width/2; slogan.y = fundo_rodape.y - 120; comoChegar_txt.y = fundo_rodape.y + 40; dicasSaude_txt.y = fundo_rodape.y + 40; fundo_rodape.y = tamStageH - fundo_rodape.height; fundo_rodape.width = tamStageW; fundo.width=stage.stageWidth; fundo.height=stage.stageHeight; } public function onResize(evt:Event):void { var sw:Number=stage.stageWidth; var sh:Number=stage.stageHeight; topo.width = sw; ////////////////////////////////////////// THUMBS thumb1.x = sw / 2 thumb1.y = topo.y + topo.height + 60; thumb2.x = thumb1.x + thumb1.width + 10; thumb2.y = thumb1.y thumb3.x = thumb2.x + thumb2.width + 10; thumb3.y = thumb1.y mulher.y = fundo_rodape.y - 440 mulher.width = sw; slogan.x = sw /2 - slogan.width/2; slogan.y = fundo_rodape.y - 120 comoChegar_txt.y = fundo_rodape.y + 40; dicasSaude_txt.y = fundo_rodape.y + 40; fundo_rodape.y = sh - fundo_rodape.height; fundo_rodape.width = tamStageW; fundo.width = sw; fundo.height = sh; } } } abraços, Compartilhar este post Link para o post Compartilhar em outros sites
italoborges 0 Denunciar post Postado Março 30, 2009 Então Lino, quando comecei no as3 tive o mesmo problema, que é o seguinte. Quando você coloca um swf externo no stage (addChild), ele ainda não tem referência do stage no momento que ele é colocado. Para você verificar isso, você precisa usar um método da classe Event ( Event.ADDED_TO_STAGE ). Com ele você verifica o momento exato que você tem acesso as propriedades do stage. Exemplo: package { import flash.display.MovieClip; public class Teste extends MovieClip { public function Teste () { trace("swf externo"); addEventListener(Event.ADDED_TO_STAGE, onInit); } private function onInit (e:Event):void { trace("adicionado"); trace(stage); } } } Pronto, essa classe Teste é um exemplo, para testá-la, basta chamar: import Teste; var teste:Teste = new Teste(); Você vai ver que os "traces" funcionarão. abrs. Compartilhar este post Link para o post Compartilhar em outros sites
linoart 0 Denunciar post Postado Março 31, 2009 valeu italoborges :) eu entendi o conceito, só que ainda na prática falta pouco... rss eu criei a classe Teste, mas onde devo chamá-la? eu chamei ela depois do swf ter carregado, mas não deu certo: function sessaoCarregado(evt:Event):void { var sessaoCarregada = evt.target.content; addChild(sessaoCarregada); import Teste; var teste:Teste = new Teste(); } tambem coloquei na função construtora do arquivo .as desse swf carregado mas deu certo. Compartilhar este post Link para o post Compartilhar em outros sites
italoborges 0 Denunciar post Postado Março 31, 2009 Não, não hehehe, a classe Teste é só um exemplo desse conceito que te falei. Você precisaria aplicar isso no seu arquivo. Por exemplo, você tem uma classe que chama o swf externo, adiciona ele no stage, e dentro dele tem uma classe também certo? Na sua classe acho que funcionaria assim: package { import flash.display.StageScaleMode; import flash.events.Event; import flash.display.MovieClip; import flash.display.*; import flash.events.ProgressEvent; import flash.events.*; import flash.net.URLRequest; import flash.events.MouseEvent; import flash.display.* import flash.events.TimerEvent; import flash.utils.Timer; import flash.text.*; import caurina.transitions.Tweener; import flash.display.StageScaleMode; import flash.display.StageAlign; import flash.display.Stage; public class cirurgia_resizeAnima extends MovieClip { private var tamStageW; private var tamStageH; public function cirurgia_resizeAnima() { addEventListener(Event.ADDED_TO_STAGE, init); } public function init (e:Event):void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = "TL"; stage.addEventListener(Event.RESIZE, onResize); tamStageW=stage.stageWidth; tamStageH=stage.stageHeight; logotipo.x = 50; menu_principal.x = 70; topo.width = tamStageW; ////////////////////////////////////////// THUMBS thumb1.x = tamStageW / 2 thumb1.y = topo.y + topo.height + 60; thumb2.x = thumb1.x + thumb1.width + 10; thumb2.y = thumb1.y thumb3.x = thumb2.x + thumb2.width + 10; thumb3.y = thumb1.y mulher.y = topo.y + topo.height + 130 mulher.width = tamStageW; slogan.x = tamStageW /2 - slogan.width/2; slogan.y = fundo_rodape.y - 120; comoChegar_txt.y = fundo_rodape.y + 40; dicasSaude_txt.y = fundo_rodape.y + 40; fundo_rodape.y = tamStageH - fundo_rodape.height; fundo_rodape.width = tamStageW; fundo.width=stage.stageWidth; fundo.height=stage.stageHeight; } public function onResize(evt:Event):void { var sw:Number=stage.stageWidth; var sh:Number=stage.stageHeight; topo.width = sw; ////////////////////////////////////////// THUMBS thumb1.x = sw / 2 thumb1.y = topo.y + topo.height + 60; thumb2.x = thumb1.x + thumb1.width + 10; thumb2.y = thumb1.y thumb3.x = thumb2.x + thumb2.width + 10; thumb3.y = thumb1.y mulher.y = fundo_rodape.y - 440 mulher.width = sw; slogan.x = sw /2 - slogan.width/2; slogan.y = fundo_rodape.y - 120 comoChegar_txt.y = fundo_rodape.y + 40; dicasSaude_txt.y = fundo_rodape.y + 40; fundo_rodape.y = sh - fundo_rodape.height; fundo_rodape.width = tamStageW; fundo.width = sw; fundo.height = sh; } } } Compartilhar este post Link para o post Compartilhar em outros sites
linoart 0 Denunciar post Postado Março 31, 2009 acho que consegui... consegui da o trace, só que o erro continua. eu coloquei a ADDED_TO_STAGE na construtora, a funcao que ele chama com os traces deu certo. mas ainda da erro. ficou dessa forma a classe package { import flash.display.StageScaleMode; import flash.events.Event; import flash.display.MovieClip; import flash.display.*; import flash.events.ProgressEvent; import flash.events.*; import flash.net.URLRequest; import flash.events.MouseEvent; import flash.display.* import flash.events.TimerEvent; import flash.utils.Timer; import flash.text.*; import caurina.transitions.Tweener; import flash.display.StageScaleMode; import flash.display.StageAlign; import flash.display.Stage; public class cirurgia_resizeAnima extends MovieClip { public function cirurgia_resizeAnima() { addEventListener(Event.ADDED_TO_STAGE, onInit); } private function onInit (e:Event):void { stage.align = "TL"; stage.addEventListener(Event.RESIZE, onResize); tamStageW=stage.stageWidth; tamStageH=stage.stageHeight; logotipo.x = 50; menu_principal.x = 70; topo.width = tamStageW; ////////////////////////////////////////// THUMBS thumb1.x = tamStageW / 2 thumb1.y = topo.y + topo.height + 60; thumb2.x = thumb1.x + thumb1.width + 10; thumb2.y = thumb1.y thumb3.x = thumb2.x + thumb2.width + 10; thumb3.y = thumb1.y mulher.y = topo.y + topo.height + 130 mulher.width = tamStageW; slogan.x = tamStageW /2 - slogan.width/2; slogan.y = fundo_rodape.y - 120; comoChegar_txt.y = fundo_rodape.y + 40; dicasSaude_txt.y = fundo_rodape.y + 40; fundo_rodape.y = tamStageH - fundo_rodape.height; fundo_rodape.width = tamStageW; fundo.width=stage.stageWidth; fundo.height=stage.stageHeight; } public function onResize(evt:Event):void { var sw:Number=stage.stageWidth; var sh:Number=stage.stageHeight; //barra_preloader.x= stage.stageWidth / 2 - barra_preloader.width /2; //barra_preloader.y=stage.stageHeight / 2 - barra_preloader.height / 2; topo.width = sw; // logotipo.x = sw /2 - logotipo.width - 100; //menu_principal.x = sw /2 - menu_principal.width /2 - 70 ////////////////////////////////////////// THUMBS thumb1.x = sw / 2 thumb1.y = topo.y + topo.height + 60; thumb2.x = thumb1.x + thumb1.width + 10; thumb2.y = thumb1.y thumb3.x = thumb2.x + thumb2.width + 10; thumb3.y = thumb1.y mulher.y = fundo_rodape.y - 440 mulher.width = sw; slogan.x = sw /2 - slogan.width/2; slogan.y = fundo_rodape.y - 120 comoChegar_txt.y = fundo_rodape.y + 40; dicasSaude_txt.y = fundo_rodape.y + 40; fundo_rodape.y = sh - fundo_rodape.height; fundo_rodape.width = tamStageW; fundo.width = sw; fundo.height = sh; } } } Compartilhar este post Link para o post Compartilhar em outros sites
italoborges 0 Denunciar post Postado Março 31, 2009 Qual a classe que você está usando para chamar este swf? Compartilhar este post Link para o post Compartilhar em outros sites
linoart 0 Denunciar post Postado Março 31, 2009 eu to chamando ele direto do .fla... todas funções de carregamento desse swf esta no .fla as classes que to usando é somente para resize e posição dos movieclips. Compartilhar este post Link para o post Compartilhar em outros sites
italoborges 0 Denunciar post Postado Março 31, 2009 Então coloca aqui o código que você tá usando para fazer o load do swf no fla. E também a chamada da classe. Compartilhar este post Link para o post Compartilhar em outros sites
linoart 0 Denunciar post Postado Março 31, 2009 eu estou fazendo o chamda da classe no painel Propiedades. não estou chamando no código. alias, esse é um problema... nunca consigo chamar uma classe no codigo. sempre diz que é esperado um parametro na classe. enfim, esse é o codigo pra fazer o load do swf: function preloaderSessao(evt:Event):void { tempoPreloaderInicial.removeEventListener(TimerEvent.TIMER, preloaderSessao) addChild(preloader); addChild(txt_preloader); var carregaSessao=new Loader(); carregaSessao.load(new URLRequest(urlSessao)); carregaSessao.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,carregan doSessao); carregaSessao.contentLoaderInfo.addEventListener(Event.COMPLETE,sessaoCarregado) ; } function carregandoSessao(evt:ProgressEvent):void { var pct:Number=Math.floor(evt.bytesLoaded * 100 / evt.bytesTotal); txt_preloader.porcentagem_txt.text=pct.toString() + "%"; var procentLoaded=evt.bytesLoaded / evt.bytesTotal * 100; preloader.scaleX=procentLoaded / 100; } function sessaoCarregado(evt:Event):void { var sessaoCarregada = evt.target.content; addChild(sessaoCarregada); } Compartilhar este post Link para o post Compartilhar em outros sites
italoborges 0 Denunciar post Postado Março 31, 2009 Lino, tenta tipar suas variáveis, dessa form é mais fácil para achar um erro. Nessa parte, tenta assim: function sessaoCarregado(evt:Event):void { var sessaoCarregada:MovieClip = evt.target.content as MovieClip; addChild(sessaoCarregada); } Agora neste swf seu, era para achar o stage, usando o listener que te falei. Na sua outra classe, comenta todo código, deixa só a construtora, e o método onInit com um trace(stage), e veja o que retorna. Abrs Compartilhar este post Link para o post Compartilhar em outros sites
linoart 0 Denunciar post Postado Março 31, 2009 você quer que eu coloque pra achar o stage no fla que carrega o swf? é que tava dando erro, ai fiz a verificação do stage na propria classe desse fla que carrega o swf (coloquei a classe ai embaixo). se precisar mesmo fazer a verificação do stage no proprio fla onde faço a chamada da classe? package { import flash.display.StageScaleMode; import flash.events.Event; import flash.display.MovieClip; import flash.display.*; import flash.events.ProgressEvent; import flash.events.*; import flash.net.URLRequest; import flash.events.MouseEvent; import flash.display.* import flash.events.TimerEvent; import flash.utils.Timer; import flash.text.*; import caurina.transitions.Tweener; import flash.display.StageScaleMode; import flash.display.StageAlign; import flash.display.Stage; public class cirurgia_resizeAnima extends MovieClip { public function cirurgia_resizeAnima() { addEventListener(Event.ADDED_TO_STAGE, onInit); } private function onInit (e:Event):void { stage.align = "TL"; stage.addEventListener(Event.RESIZE, onResize); tamStageW=stage.stageWidth; tamStageH=stage.stageHeight; logotipo.x = 50; menu_principal.x = 70; topo.width = tamStageW; ////////////////////////////////////////// THUMBS thumb1.x = tamStageW / 2 thumb1.y = topo.y + topo.height + 60; thumb2.x = thumb1.x + thumb1.width + 10; thumb2.y = thumb1.y thumb3.x = thumb2.x + thumb2.width + 10; thumb3.y = thumb1.y mulher.y = topo.y + topo.height + 130 mulher.width = tamStageW; slogan.x = tamStageW /2 - slogan.width/2; slogan.y = fundo_rodape.y - 120; comoChegar_txt.y = fundo_rodape.y + 40; dicasSaude_txt.y = fundo_rodape.y + 40; fundo_rodape.y = tamStageH - fundo_rodape.height; fundo_rodape.width = tamStageW; fundo.width=stage.stageWidth; fundo.height=stage.stageHeight; } public function onResize(evt:Event):void { var sw:Number=stage.stageWidth; var sh:Number=stage.stageHeight; //barra_preloader.x= stage.stageWidth / 2 - barra_preloader.width /2; //barra_preloader.y=stage.stageHeight / 2 - barra_preloader.height / 2; topo.width = sw; // logotipo.x = sw /2 - logotipo.width - 100; //menu_principal.x = sw /2 - menu_principal.width /2 - 70 ////////////////////////////////////////// THUMBS thumb1.x = sw / 2 thumb1.y = topo.y + topo.height + 60; thumb2.x = thumb1.x + thumb1.width + 10; thumb2.y = thumb1.y thumb3.x = thumb2.x + thumb2.width + 10; thumb3.y = thumb1.y mulher.y = fundo_rodape.y - 440 mulher.width = sw; slogan.x = sw /2 - slogan.width/2; slogan.y = fundo_rodape.y - 120 comoChegar_txt.y = fundo_rodape.y + 40; dicasSaude_txt.y = fundo_rodape.y + 40; fundo_rodape.y = sh - fundo_rodape.height; fundo_rodape.width = tamStageW; fundo.width = sw; fundo.height = sh; } } } abraço, Compartilhar este post Link para o post Compartilhar em outros sites
linoart 0 Denunciar post Postado Março 31, 2009 ahhh estou tipando as variaveis... muitas vezes esqueço : :huh: :D Compartilhar este post Link para o post Compartilhar em outros sites
italoborges 0 Denunciar post Postado Abril 1, 2009 A classe que você quer acessar o stage é a do swf externo certo? Então continue chamando o swf externo normalmente, e a classe também, mas nesta classe comente todo código e só deixe a função construtora e a init com o trace. package { import flash.display.StageScaleMode; import flash.events.Event; import flash.display.MovieClip; import flash.display.*; import flash.events.ProgressEvent; import flash.events.*; import flash.net.URLRequest; import flash.events.MouseEvent; import flash.display.* import flash.events.TimerEvent; import flash.utils.Timer; import flash.text.*; import caurina.transitions.Tweener; import flash.display.StageScaleMode; import flash.display.StageAlign; import flash.display.Stage; public class cirurgia_resizeAnima extends MovieClip { public function cirurgia_resizeAnima() { addEventListener(Event.ADDED_TO_STAGE, onInit); } private function onInit (e:Event):void { trace(stage); } } } Veja o que acontece agora. abrs Compartilhar este post Link para o post Compartilhar em outros sites
linoart 0 Denunciar post Postado Abril 1, 2009 entao, dá certo... mas o erro continua. será que o erro não é outra coisa? porque o resize ta funcionando normalmente, mesmo com o erro. sem querer abusar muito, mas posso te enviar por em email o arquivo pra você dar uma olhada? senão tudo bem :) se puder, me manda um email que eu te encaminho o arquivo: lino22@gmail.com outra coisa, quando eu carrego o swf nele tem um menu, só que quando é carregado os menus não funcionam. eu preciso fazer algo parececido com ADDED_TO_STAGE que você me disse? por exemplo passando o MouseEvent. abraço, Compartilhar este post Link para o post Compartilhar em outros sites
italoborges 0 Denunciar post Postado Abril 1, 2009 Te mandei email Lino. Abrs Compartilhar este post Link para o post Compartilhar em outros sites