Groups > Multimedia > Macromedia Open SWF discussion > Loading a SWF from another SWF




Loading a SWF from another SWF

Loading a SWF from another SWF
Thu, 24 Apr 2008 04:33:27 +000
I want to load a SWF form another SWF and a have one error:

 TypeError: Error #1009: Cannot access a property or method of a null object 
reference.
 at MoverBall$iinit()

 Any help?

 here is the actionscript code:

 package {
 import flash.display.*;
 import flash.events.*;
 import flash.events.KeyboardEvent;
 import flash.ui.Keyboard;
 import flash.geom.Point;

 public class MoverBall extends MovieClip{

 private var gameSprite:Sprite;
 private var ball:Ball2;
 private var xpos:Number = 0;
 private var ypos:Number = 0;
 private var zpos:Number = 0;
 private var vx:Number = 0;
 private var vy:Number = 0;
 private var vz:Number = 0;
 private var friction:Number = .95;
 private var fl:Number = 250;
 private var vpX:Number = stage.stageWidth / 2;
 private var vpY:Number = stage.stageHeight / 2;

 public function MoverBall(){

 // INICIALIZAR SPRITE
 gameSprite = new Sprite();
 ball = new Ball2();

 stage.addChild(gameSprite);
 gameSprite.addChild(ball);
 addEventListener(Event.ENTER_FRAME, onEnterFrame);
 stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
 }

 function onEnterFrame(event:Event):void{
 xpos += vx;
 ypos += vy;
 zpos += vz;
 vx *= friction;
 vy *= friction;
 vz *= friction;
 if(zpos > -fl){
 var scale:Number = fl / (fl + zpos);
 ball.scaleX = ball.scaleY = scale;
 ball.x = vpX + xpos * scale;
 ball.y = vpY + ypos * scale;
 ball.setCentro(new Point(ball.x+10, ball.y+10));
 ball.visible = true;
 }
 else{
 ball.visible = false;
 }
 }
 function onKeyDown(event:KeyboardEvent):void{
 switch(event.keyCode){
 case Keyboard.UP :
 vy -= 1;
 break;
 case Keyboard.DOWN :
 vy += 1;
 break;
 case Keyboard.LEFT :
 vx -= 1;
 break;
 case Keyboard.RIGHT :
 vx += 1;
 break;
 case Keyboard.SHIFT :
 vz += 1;
 break;
 case Keyboard.CONTROL :
 vz -= 1;
 break;
 default :
 break;
 }
 }

 function getBall(){
 return ball;
 }
 }
 }

 *******************************************
 the Ball2 code:

 package {
 import flash.display.*;
 import flash.geom.Point;
 import flash.display.*;

 public class Ball2 extends MovieClip{

 private var centro:Point;
 private var aux:int;

 public function Ball2(){
 graphics.beginFill(0xff0000);
 graphics.drawCircle(0,0,10);
 graphics.endFill();
 this.x=100;
 this.y=100;
 centro = new Point(this.x+10, this.y+10);

 aux=1234;
 }

 public function getCentro(){
 return centro;
 }

 public function getVar():int{
 return aux;
 }

 public function setCentro(c:Point){
 centro=c;
 }
 }
 }

 ****************************************************************
 And the code in my FLA is:

 // Request the content
 var url:URLRequest = new URLRequest("Ball2.swf");

 // Create a loader object
 var loader:Loader = new Loader();

 // Load the content
 loader.load(url);

 // Add loader into the Display List
 addChild(loader);

Post Reply
about | contact