Fabrici0 0 Denunciar post Postado Fevereiro 6, 2008 Olá pessoal, preciso criar variáveis com "string" + "num dinâmico" em action script 3, mas não estou conseguindo. Abaixo o código: for(var i:Number=0; i<10; i++ ){ var nome+i:TextInput = new TextInput(); vb.addChild(textInput); } Estou utilizando flex, vlw! Compartilhar este post Link para o post Compartilhar em outros sites
Eder Fortunato 15 Denunciar post Postado Fevereiro 7, 2008 testa assim: for(var i:Number=0; i<10; i++ ){ this["nome" + i] = new TextInput(); vb.addChild(this["nome" + i] as TextInput ); } []´s Compartilhar este post Link para o post Compartilhar em outros sites
Fabrici0 0 Denunciar post Postado Fevereiro 7, 2008 testa assim: for(var i:Number=0; i<10; i++ ){ this["nome" + i] = new TextInput(); vb.addChild(this["nome" + i] as TextInput ); } []´s Para compilar não tem erro, mas na hora de rodar o swf surge um erro: ReferenceError: Error #1056: Cannot create property nome0 on teste. Código completo: <mx:Script> <![CDATA[ import mx.controls.TextInput; import mx.containers.VBox; public function test():void{ var larX:Number = 20; var vb:VBox = new VBox(); for(var i:Number=0; i<10; i++ ){ this["nome" + i] = new TextInput(); this["nome" + i].x = larX + i; vb.addChild(this["nome" + i]); } } ]]> </mx:Script> Erro: ReferenceError: Error #1056: Cannot create property nome0 on teste. at teste/test() at teste/___Application1_applicationComplete() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent() at mx.managers::SystemManager/::preloader_preloaderDoneHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.preloaders::Preloader/::displayClassCompleteHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.preloaders::DownloadProgressBar/::timerHandler() at mx.preloaders::DownloadProgressBar/::initCompleteHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.preloaders::Preloader/::dispatchAppEndEvent() at mx.preloaders::Preloader/::appCreationCompleteHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent() at mx.core::UIComponent/set initialized() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() Compartilhar este post Link para o post Compartilhar em outros sites
Eder Fortunato 15 Denunciar post Postado Fevereiro 7, 2008 veja agora: <mx:Script> <![CDATA[ import mx.controls.TextInput; import mx.containers.VBox; public function test():void{ var larX:Number = 20; var vb:VBox = new VBox(); for(var i:Number=0; i<10; i++ ){ var campo:TextInput = new TextInput(); campo.name = "nome" + i campo.x = larX + i; vb.addChild( campo); } addChild(vb) } ]]> </mx:Script> []´s Compartilhar este post Link para o post Compartilhar em outros sites
Fabrici0 0 Denunciar post Postado Fevereiro 8, 2008 Muito obrigado, Eder. Funcionou corretamente. ;) Compartilhar este post Link para o post Compartilhar em outros sites
Martin Fabichak 0 Denunciar post Postado Abril 5, 2008 Em as3 o que conta mesmo é o name. Depois, para pegaro campo criado, basta fazer getChildByName("nome1"); é realmente MUITO melhor do que AS2 =P Compartilhar este post Link para o post Compartilhar em outros sites