RODESIGN 0 Denunciar post Postado Agosto 5, 2010 Olá a todos, preciso de ajuda para resolver o seguinte problema: Tenho 3 ficheiros - index (ficheiro principal, raiz do site) - galeria.swf (galeria de imagens com xml) - polaroids.as (documento de class interligado com o ficheiro galeria.swf) Tenho tentado (sem sucesso) fazer o load do ficheiro galeria.swf para o stage do index mas surge sempre o seguinte erro: TypeError: Error #1009: Não é possível acessar uma propriedade ou um método de uma referência de objeto nula. at Polaroids() Alguém pode ajudar, por favor? Compartilhar este post Link para o post Compartilhar em outros sites
Thiago de Oliveira Cruz 21 Denunciar post Postado Agosto 5, 2010 Código que está sendo utilizado por favor :)/> Como você ta carregando esse arquivo galeria.swf e como foi chamado esse polaroids.as dentro da galeria. Se não num tem como ajudar... Abraços Compartilhar este post Link para o post Compartilhar em outros sites
RODESIGN 0 Denunciar post Postado Agosto 6, 2010 desde já muito obrigado pela ajuda. o código do polaroids.as é o seguinte: package { import flash.display.*; import flash.filters.*; import flash.utils.*; import flash.net.*; import flash.events.*; import flash.filters.DropShadowFilter; import caurina.transitions.*; public class Polaroids extends MovieClip { //Variables public var stageContainer:MovieClip; private var _scaleTempo:Number; private var _thumbStr:Number; private var _stageHeight:Number; private var _stageWidth:Number; private var _count:Number; //Arrays private var _imagesArr:Array; private var _imageCatArr:Array; private var _imageRefArr:Array; //Bitmaps private var _image:Bitmap; private var _bitmap:BitmapData; //XML private var _xmlLoader:URLLoader; private var _imageXML:XML; //Holders private var _imageContainer:ImageContainer; //Image States private var _activeImage = null; private var _previousActiveImage = null; public function Polaroids() { //sets up initial variable values _count = 0; _imagesArr=new Array(); _imageCatArr = new Array(); _imageRefArr = new Array(); _scaleTempo=6; _thumbStr = .3; _stageHeight=stage.stageHeight; _stageWidth=stage.stageWidth; stageContainer = new MovieClip(); addChild(stageContainer); init(); } //Add Stage Listener private function addedToStage(e:Event):void { stage.addEventListener(Event.RESIZE, onResize); } /*************************************************************************** Initialise ***************************************************************************/ private function init():void { //Setup stage //stage.align = StageAlign.TOP_LEFT; //stage.scaleMode = StageScaleMode.NO_SCALE; //Load XML var _xmlLoader:URLLoader=new URLLoader; _xmlLoader.load(new URLRequest("images.xml")); _xmlLoader.addEventListener(Event.COMPLETE,processXML); this.addEventListener(Event.ADDED_TO_STAGE, addedToStage); } /*************************************************************************** Process XML ***************************************************************************/ private function processXML(e:Event):void { _imageXML=new XML(e.target.data); var catCount:int = 0; for (var i:int=0; i < _imageXML.category.length(); i++) { _imageCatArr.push(_imageXML.category[i].@cat); catCount = i; for (var j:int=0; j < _imageXML.category[catCount].*.length(); j++) { _imageRefArr.push([_imageXML.category[catCount].@cat, _imageXML.category[catCount].image[j].@url, _imageXML.category[catCount].image[j].@caption]); } } loadImages(0); } /*************************************************************************** Unload Images ***************************************************************************/ private function unloadImages(e:Event):void { for (var i:int = 0; i<_imagesArr.length; i++) { stageContainer.removeChild(DisplayObject(_imagesArr[i])); } _imagesArr = []; _activeImage = null; _previousActiveImage = null; loadImages(e.currentTarget.id); } /*************************************************************************** Load Images ***************************************************************************/ private function loadImages(ref:int):void { _count = 0; for (var i:int=0; i < _imageRefArr.length; i++) { if (_imageRefArr[i][0] == _imageCatArr[ref]) { var imageLoader:Loader=new Loader; imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,addImage); imageLoader.load(new URLRequest(_imageRefArr[i][1])); _imageContainer = new ImageContainer(); _imageContainer.falseBtn.buttonMode = true; _imageContainer.falseBtn.doubleClickEnabled = true; _imageContainer.imageHolder.addChild(imageLoader);//Add Bitmap to a MoviClip _imageContainer _imageContainer.imageCaption.text = _imageRefArr[i][2]; //Setup Attributes _imageContainer.id = _count; _imageContainer.addEventListener(MouseEvent.MOUSE_DOWN,dragImage); _imageContainer.addEventListener(MouseEvent.MOUSE_UP,dropImage); _imageContainer.addEventListener(MouseEvent.MOUSE_OUT, dropImage); _imageContainer.falseBtn.addEventListener(MouseEvent.DOUBLE_CLICK, setup_activeImage); _imagesArr[_count]=_imageContainer;//Add image reference to an Array _imageContainer.filters = [new DropShadowFilter(0,0,0,.9,8,8,1,1,false,false)]; //Button Listeners _imageContainer.nextBtn.visible = false; _imageContainer.previousBtn.visible = false; _imageContainer.nextBtn.buttonMode = true; _imageContainer.previousBtn.buttonMode = true; _imageContainer.nextBtn.addEventListener(MouseEvent.MOUSE_DOWN, nextImage); _imageContainer.previousBtn.addEventListener(MouseEvent.MOUSE_DOWN, previousImage); _imageContainer.alpha = 0; //Add Container to Stage addChild(_imageContainer); stageContainer.addChild(_imageContainer); _count++; } } } /*************************************************************************** Add images to MovieClip on Stage ***************************************************************************/ private function addImage(e:Event):void { _image=Bitmap(e.target.content); var imageParent:Object = new Object(); imageParent = _image.parent.parent.parent; _bitmap=_image.bitmapData; _image.smoothing = true; _image.x = imageParent.width/2 - (_image.width/2 + 15); _image.y = imageParent.height/2 - (_image.height/2 + 80) ; imageParent.scaleX = _thumbStr; imageParent.scaleY = _thumbStr; imageParent.rotation = 30 - 60 * Math.random(); if (Math.round(Math.random() * 1) == 1) { imageParent.y=stage.stageHeight * Math.random() + imageParent.height * 2; if (Math.round(Math.random() * 1) == 1) { imageParent.x=stage.stageWidth + imageParent.width * 2; } else { imageParent.x=- imageParent.width * 2; } } else { imageParent.x=stage.stageWidth * Math.random() + imageParent.width * 2; if (Math.round(Math.random() * 1) == 1) { imageParent.y=stage.stageHeight + imageParent.height * 2; } else { imageParent.y=- imageParent.height * 2; } } imageParent.newX = Math.round((imageParent.width/2) + (stage.stageWidth-imageParent.width)*Math.random()); imageParent.newY = Math.round((imageParent.height/2) + (stage.stageHeight-imageParent.height)*Math.random()); imageParent.oldRotation = imageParent.rotation; imageParent.oldX = imageParent.newX; imageParent.oldY = imageParent.newY; imageParent.startX = imageParent.x; imageParent.startY = imageParent.y; imageParent.oldHeight = imageParent.scaleY; imageParent.oldWidth = imageParent.scaleX; animateImage(imageParent); } /*************************************************************************** Animate Images onto Stage ***************************************************************************/ private function animateImage(m:Object):void { Tweener.addTween(m,{x: m.newX, y: m.newY, time: 1.5 }); Tweener.addTween(m,{alpha:1, time: 1}); } /*************************************************************************** Drag & Drop Images ***************************************************************************/ private function dragImage(e:MouseEvent) { if (e.currentTarget != _activeImage) { e.currentTarget.startDrag(); if (_activeImage == null) { stageContainer.setChildIndex(DisplayObject(e.currentTarget), stageContainer.numChildren-1); } else { stageContainer.setChildIndex(DisplayObject(e.currentTarget), stageContainer.numChildren-2); } } } private function dropImage(e:MouseEvent) { if (e.currentTarget != _activeImage) { e.currentTarget.stopDrag(); e.currentTarget.oldX = e.currentTarget.x; e.currentTarget.oldY = e.currentTarget.y; } } /*************************************************************************** onResize Handler ***************************************************************************/ private function onResize(e:Event):void { for (var i:int = 0; i<_imagesArr.length; i++) { if (_imagesArr[i] != _activeImage) { _imagesArr[i].x = Math.round(stage.stageWidth * (_imagesArr[i].x/_stageWidth)); _imagesArr[i].y = Math.round(stage.stageHeight * (_imagesArr[i].y/_stageHeight)); } else { _activeImage.x = stage.stageWidth/2; _activeImage.y = stage.stageHeight/2; } _imagesArr[i].oldX = Math.round(stage.stageWidth * (_imagesArr[i].oldX/_stageWidth)); _imagesArr[i].oldY = Math.round(stage.stageHeight * (_imagesArr[i].oldY/_stageHeight)); _imagesArr[i].newX = Math.round(stage.stageWidth * (_imagesArr[i].newX/_stageWidth)); _imagesArr[i].newY = Math.round(stage.stageHeight * (_imagesArr[i].newY/_stageHeight)); _imagesArr[i].startX = Math.round(stage.stageWidth * (_imagesArr[i].startX/_stageWidth)); _imagesArr[i].startY = Math.round(stage.stageHeight * (_imagesArr[i].startY/_stageHeight)); } _stageWidth = stage.stageWidth; _stageHeight = stage.stageHeight; } /*************************************************************************** Handle Selected Image ***************************************************************************/ private function zoomImage():void { stageContainer.setChildIndex(_activeImage, stageContainer.numChildren-1); Tweener.addTween(_activeImage,{scaleX: 1, scaleY: 1, rotation: 0, x: _stageWidth/2 , y: _stageHeight/2, time: 1}); _activeImage.nextBtn.visible = true; _activeImage.previousBtn.visible = true; } private function returnImage():void { stageContainer.setChildIndex(_previousActiveImage, stageContainer.numChildren-2); Tweener.addTween(_previousActiveImage,{scaleX: .3, scaleY: .3, rotation: _previousActiveImage.newRotation, x: _previousActiveImage.newX , y: _previousActiveImage.newY, time: 1}); _previousActiveImage.nextBtn.visible = false; _previousActiveImage.previousBtn.visible = false; } private function setup_activeImage(e:Event):void { if ((_activeImage == null) && (_previousActiveImage == null)) { _activeImage = e.currentTarget.parent; zoomImage(); } else if (e.currentTarget.parent != _activeImage) { _previousActiveImage = _activeImage; _activeImage = e.currentTarget.parent; zoomImage(); returnImage(); } else { Tweener.addTween(_activeImage,{scaleX: .3, scaleY: .3, rotation: _activeImage.oldRotation, x: _activeImage.newX , y: _activeImage.newY, time: 1}); _activeImage.nextBtn.visible = false; _activeImage.previousBtn.visible = false; _activeImage = null; _previousActiveImage = null; } } /*************************************************************************** Button Handlers ***************************************************************************/ private function nextImage(e:MouseEvent):void { var imageID = int(e.currentTarget.parent.id); if (imageID < _imagesArr.length - 1) { _previousActiveImage = e.currentTarget.parent; _activeImage = _imagesArr[imageID+1]; zoomImage(); returnImage(); } else { _previousActiveImage = e.currentTarget.parent; _activeImage = _imagesArr[0]; zoomImage(); returnImage(); } } private function previousImage(e:MouseEvent):void { var imageID = int(e.currentTarget.parent.id); if (imageID != 0) { _previousActiveImage = e.currentTarget.parent; _activeImage = _imagesArr[imageID-1]; zoomImage(); returnImage(); } else { _previousActiveImage = e.currentTarget.parent; _activeImage = _imagesArr[_imagesArr.length-1]; zoomImage(); returnImage(); } } } } Compartilhar este post Link para o post Compartilhar em outros sites
Andre Cocuroci 0 Denunciar post Postado Agosto 6, 2010 Esse código está no document class ou você tá importando no primeiro frame? Compartilhar este post Link para o post Compartilhar em outros sites
RODESIGN 0 Denunciar post Postado Agosto 9, 2010 Está no document class Compartilhar este post Link para o post Compartilhar em outros sites
Andre Cocuroci 0 Denunciar post Postado Agosto 9, 2010 Acho que o erro está no construtor da classe, nessas duas linhas: _stageHeight=stage.stageHeight; _stageWidth=stage.stageWidth; Acho que poderia tirar elas do construtor e colocar na função addedToStage. Pelo que entendi alguma propriedade não está disponivel ao chamar a classe e deve ser o stage. Compartilhar este post Link para o post Compartilhar em outros sites
RODESIGN 0 Denunciar post Postado Agosto 9, 2010 fiz a alteração que sugeriste mas apareceu-me um outro erro que também não consegui resolver. Tens alguma ideia do que pode estar a gerar o seguinte erro: Error #2044: ioError: não manipulado. text=Error #2032: Erro de fluxo. URL: file:///C|/.../Site/images.xml at Polaroids/init() at Polaroids() Desde já muito obrigado pela ajuda! Compartilhar este post Link para o post Compartilhar em outros sites
Andre Cocuroci 0 Denunciar post Postado Agosto 9, 2010 Não está achando o arquivo images.xml. Precisa estar na mesma pasta do fla e swf. Compartilhar este post Link para o post Compartilhar em outros sites
RODESIGN 0 Denunciar post Postado Agosto 11, 2010 Olá! já está resolvido. Bastou colocar o images.xml no mesmo directório que o .fla/.swf principal em vez de na pasta onde se encontram os ficheiros da galeria. muito obrigado pela ajuda. Em breve o site vai estar online em www.alexandrerola.com (para já está apenas uma versão desactualizada). Compartilhar este post Link para o post Compartilhar em outros sites