Skip to main content
Known Participant
February 4, 2011
Question

loading XML images

  • February 4, 2011
  • 2 replies
  • 1497 views

im writting the following code, all works fine until i load the images CHICA every time i press are loaded and

when i try to load the images GRANDE doesnt work coould any one help me please

thanks

package{

import flash.events.Event;
// punto de luz
import org.papervision3d.lights.PointLight3D;
// sombra
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
// materiales
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.WireframeMaterial;

// primitivos
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.BasicView;

// eventos
import flash.events.Event;
import org.papervision3d.events.InteractiveScene3DEvent;
import flash.events.MouseEvent;

import caurina.transitions.Tweener;
       
import org.papervision3d.materials.*;

import org.papervision3d.objects.DisplayObject3D;

import org.papervision3d.render.QuadrantRenderEngine;

import flash.display.*; 
import flash.net.URLRequest;
import flash.net.URLLoader;


[SWF(width="800", height="600", frameRate="40")]

public class a2 extends BasicView{

   
private var imagenes:XML;        
private var cargaImagenes:URLLoader;   
private var cargaChicas:Loader;   
private var urlChicas:String;
private var urlGrandes:String;   
private var columnas:Number;   
private var miX:Number;   
private var miY:Number;   
private var chicaAncho:Number;   
private var chicaAlto:Number;   
private var misImagenes:XMLList;  
private var miTotal:Number;       
private var contiene:MovieClip;       

private var x_cuenta:Number = 0;
private var y_cuenta:Number = 0;

    private var piso:Plane;
    private var materialPiso:WireframeMaterial;

    private var edificio1:Cube;
    private var techo1:Plane;
   
    private var edificio2:Cube;
   
   
    private var puntoLuz:PointLight3D;
    private var sombra:FlatShadeMaterial;
    private var sombra2:FlatShadeMaterial;
     
    private var sombraRecambio:FlatShadeMaterial;
    private var sombraRecambio2:FlatShadeMaterial;
   
    private var colorBoton:ColorMaterial;
    private var botonDerecho:Plane;

   
    public function a2(){

     var cargaXML:URLRequest = new URLRequest("prueba.xml");     
     cargaImagenes = new URLLoader( );    
     cargaImagenes.addEventListener(Event.COMPLETE, procesaXML);     
     cargaImagenes.load(cargaXML);

    super(stage.stageWidth,stage.stageHeight,true,true);

    renderer = new QuadrantRenderEngine();      

    viewport.interactive = true;
   
    // puntos de luz
        puntoLuz = new PointLight3D(true);
        puntoLuz.x = 200;
        puntoLuz.y = 800;
        puntoLuz.z = -400;  
   
    // botones p
    colorBoton = new ColorMaterial(0xff0000);
    colorBoton.interactive = true;
    botonDerecho = new Plane(colorBoton, 100, 30, 2, 2);
    botonDerecho.x= 500;
    botonDerecho.y= -650;
 
    scene.addChild(botonDerecho);

   
    // sombra edificios
       
      sombra = new FlatShadeMaterial(puntoLuz, 0xccc, 0x999);
      sombraRecambio = new FlatShadeMaterial (puntoLuz, 0xccc, 0x0ff);
     
      sombra.interactive = true;
      sombraRecambio.interactive = true;

   
 
 
     // piso
     var materialPiso:WireframeMaterial = new WireframeMaterial(0x000000,1,2);
      piso = new Plane (materialPiso, 800, 1200, 2, 2);
      piso.x = 10;
      piso.y = 30;
//  OJO CON ESTO --->>>>>>>>>>>>>>>>>>>>>>
        piso.localRotationX = -Math.atan2(piso.x,piso.z) * 150 / Math.PI; 
        scene.addChild(piso);


// edificios
        edificio1 = new Cube(new MaterialsList({all:sombra}), 80, 100, 150);
        edificio1.x = -400;
        edificio1.y = -525;
            piso.addChild(edificio1);

        techo1 = new Plane (sombra, 140, 180, 2, 2);
        techo1.z= -57;
        techo1.y=-525;
        techo1.x=-400;
          piso.addChild(techo1);  
   
        edificio2 = new Cube(new MaterialsList({all:sombra}), 120, 80, 80);   
        edificio2.x= -300;
        edificio2.y = -562;
        edificio2.z = 8;
    piso.addChild(edificio2);
   
     startRendering();
       
  // ??? techo interactivo?????? --------------->
        techo1.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, adentro);
        techo1.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,fuera);
       edificio1.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,adentro);
       edificio1.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, fuera);
       edificio1.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, edificio1Click);
       
       
      edificio2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,adentro2);
      edificio2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,fuera2);
      
        botonDerecho.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onClick);
}           

    private function onClick(e:InteractiveScene3DEvent):void
        {
            if (!Tweener.isTweening(e.displayObject3D))
            {
                var giraDerecha:DisplayObject3D = piso;           
                Tweener.addTween(giraDerecha,{
                    localRotationZ:giraDerecha.localRotationZ + 90,
                    time:1
                });
            }
        }


       
     private function adentro(e:InteractiveScene3DEvent):void
        {
            techo1.material = sombraRecambio;
            edificio1.material = sombraRecambio;
        }   
       
        private function fuera(e:InteractiveScene3DEvent):void
        {
            techo1.material = sombra;
            edificio1.material = sombra;
        }
       
        private function edificio1Click(e:InteractiveScene3DEvent):void
        {
        llamaChicas();
trace("ouch");
        }
       
       
       
        private function adentro2(e:InteractiveScene3DEvent):void
        {
            edificio2.material = sombraRecambio;
           
        }   
       
        private function fuera2(e:InteractiveScene3DEvent):void
        {
            edificio2.material = sombra;
        }   
       
       
    override protected function onRenderTick(event:Event=null):void{
        // cube1.yaw(0.5);        
        // cube1.pitch(1);
        // cube1.roll(1);         
     
        renderer.renderScene(scene, camera, viewport);
        }
     private function procesaXML(e:Event):void {                  
      imagenes = new XML(e.target.data);               
     columnas = imagenes.@COLUMNAS;       
     miX = imagenes.@POSICIONX;      
      miY = imagenes.@POSICIONY;       
     chicaAncho = imagenes.@ANCHO;       
     chicaAlto = imagenes.@ALTO;       
     misImagenes = imagenes.IMAGEN;      
      miTotal = misImagenes.length();               

     contenedor();      
      // llamaChicas();                                      
     }  

     private function contenedor():void {       
     contiene = new MovieClip();       
     contiene.x = miX;       
     contiene.y = miY;       
     addChild(contiene); 

     contiene.addEventListener(MouseEvent.CLICK, agranda);

     }     
   
      private function llamaChicas():void {       
          for (var i:Number = 0; i < miTotal; i++){            
               urlChicas = misImagenes.@CHICA;         
           cargaChicas = new Loader();

               cargaChicas.load(new URLRequest(urlChicas));               
                cargaChicas.contentLoaderInfo.addEventListener(Event.COMPLETE,  listaChicas);  
              
            //    cargaChicas.name = i;

                 // calcula el ancho
                cargaChicas.x = (chicaAncho+10)*x_cuenta;
                cargaChicas.y = (chicaAlto+10)*y_cuenta;

               if (x_cuenta+1 < columnas){
                      x_cuenta++;
                } else {
                    x_cuenta = 0;
                    y_cuenta++
                }  
                              
          } 
     }      

        private function listaChicas(e:Event):void{           
         var chica:Loader = Loader(e.target.loader);                    
         contiene.addChild(chica);      
     }
       
        private function agranda(e:MouseEvent):void{
trace("agranda");
var cargaGrandes:Loader = new Loader();
        var urlGrandes = misImagenes[e.target.name].@GRANDE;

        cargaGrandes.load(new URLRequest(urlGrandes));
        cargaGrandes.contentLoaderInfo.addEventListener(Event.INIT, grandeLista);
        }

        private function grandeLista(e:Event):void{
        var mi_cargador:Loader = Loader(e.target.loader);
        addChild(mi_cargador);
        mi_cargador.x = (stage.stageWidth - mi_cargador.width)/2;
        mi_cargador.y = (stage.stageHeight - mi_cargador.height)/2;
        }

    }
}

This topic has been closed for replies.

2 replies

Known Participant
February 7, 2011

Andrei

I ereased the var the error in the output window doesnt appear, but contiene when is cliecked doesnt show the images

in

Inspiring
February 8, 2011

What does trace show?

private function grandeLista(e:Event):void {
     var mi_cargador:Loader = Loader(e.target.loader);
     trace(mi_cargador);
     addChild(mi_cargador);
     mi_cargador.x = (stage.stageWidth - mi_cargador.width)/2;
     mi_cargador.y = (stage.stageHeight - mi_cargador.height)/2;
}

Known Participant
February 8, 2011

Dear Andrei I have test the following

private function agranda(e:MouseEvent):void{
     -->   trace("agranda");
        var cargaGrandes:Loader = new Loader();   
        urlGrandes = misImagenes[e.target.name].@GRANDE;
        // trace(misImagenes[e.target.name].@GRANDE);
        // trace(e.currentTarget.name);
     -->  trace(urlGrandes);
        cargaGrandes.contentLoaderInfo.addEventListener(Event.INIT, grandeLista);
        cargaGrandes.load(new URLRequest(urlGrandes));
        }
        private function grandeLista(e:Event):void{
    -->    trace("agranda")
        var mi_cargador:Loader = Loader(e.target.loader);
      -->  trace(mi_cargador);
        mi_cargador.x = (stage.stageWidth - mi_cargador.width)/2;
        mi_cargador.y = (stage.stageHeight - mi_cargador.height)/2;
        addChild(mi_cargador);
        }

------------------

   trace("agranda"); // output "agranda" is OK

   trace(urlGrandes); // doesnt output nothing bad : (

   trace("agranda");  // doesnt output nothing bad : (

   trace(mi_cargador); // doesnt output nothing bad : (

i change the images from direcotory also @chicas and @grandes were in the same but th same problem appear

Its suposed the load same image but a bigger one than @chicas, maybe I mess something?

Inspiring
February 5, 2011

First, note the sequence (listeners should be added BEFORE load() is called), second - use COMPLETE - not INIT:

cargaGrandes.contentLoaderInfo.addEventListener(Event.COMPLETE, grandeLista);
cargaGrandes.load(new URLRequest(urlGrandes));

Known Participant
February 7, 2011

Thanks Andrei

I made some corrections to the code:

var urlGrandes = misImagenes[e.target.name].@GRANDE;
cargaGrandes.contentLoaderInfo.addEventListener(Event.COMPLETE, grandeLista);
cargaGrandes.load(new URLRequest(urlGrandes));

-------

Also I declared a new private variable filas

private var filas:Number;

and wrote in the XML file too so the problem of displaying the imagens in "Y" was solved these way:

if (x_cuenta+1 < columnas){
                      x_cuenta++;
                } else {
                    x_cuenta = 0;
                    y_cuenta++
                }  
               if (y_cuenta+1 > filas)
                   y_cuenta = 0              
          }

------------------------

But the loading with a Mouse Event of grande still persist,

On the Output windows it appear an error:

1008: varible 'URLGrandes' has no type of declaration

The varialbe is declare after the class

private var urlGrandes:String;

Did I made something wrong?

Inspiring
February 7, 2011

Whenever you use keyword "var" you declare a new variable. Although you can declare only one variable with the same name in the same scope, in classes functions can see class' scope and their own scopes. Thus, class' private var urlGrandes is a different variable from the one you declared in function agranda - hence compiler error. So, either remove word var before urlGrandes in agranda or make it String.