A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Help needed with loading external swf file

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    18

    Smile Help needed with loading external swf file

    Hi, everyone. I created a game ( a fla file and 4 actionscript files, there are 4 movieclip symbol in libirary linkage pointed to the 4 actionscript files).
    So far, everything is fine, I tested the movie, and the game worked just fine.
    But after I created another fla file as preloader to load the previous fla file, I received error message:
    [
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at extramecartrace_fla::MainTimeline/eventStage()
    TypeError: Error #2007: Parameter hitTestObject must be non-null.
    at flash.display:isplayObject/flash.displayisplayObject::_hitTest()
    at flash.display:isplayObject/hitTestObject()
    at AIcar/enterFrameAction()
    ]

    here is my code inside of the preloader fla file:
    var myURL:URLRequest= new URLRequest("extrame car trace.swf");
    var myLoader:Loader= new Loader();
    myLoader.load(myURL);
    addChild(myLoader);

    Can anyone help , I don't have any idea what's wrong?
    thanks.

  2. #2
    Member
    Join Date
    May 2007
    Posts
    35
    myLoader.load(myURL);
    addChild(myLoader);

    Try switching these two lines. I can explain further if you want

  3. #3
    Junior Member
    Join Date
    Mar 2007
    Posts
    18
    I tried switching them , but i still get the same Error message!

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Can you be more specific what you load into what and in which context the scripts are.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Junior Member
    Join Date
    Mar 2007
    Posts
    18
    It's like this :
    the main fla is "extrame car trace.fla" and there are 4 external AS files in the same folder : AIcar.as, playerCar.as, Timer.as, roadLane.as
    so far, the they work fine, then i created a fla fiel called "Loader.fla" to load "extrame car trace.swf"
    ////////
    code inside Loader.fla //first frame on main timeline//)
    var myURL:URLRequest= new URLRequest("extrame car trace.swf");
    var myLoader:Loader= new Loader();
    myLoader.load(myURL);
    addChild(myLoader);
    ////////////////////////////////
    here is the code inside AIcar.as:
    package {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.events.Event;

    public class AIcar extends MovieClip {
    private var parent1:Object;
    public var _status:Boolean;

    public function AIcar() {
    init();

    }
    private function init():void {
    _status=true;
    parent1= this.parent;
    this.addEventListener(Event.ENTER_FRAME , enterFrameAction);
    }
    public function enterFrameAction(event:Event):void {
    if (_status==true) {
    if (parent1._hitAction==false) {
    this.y+=parent1._speed*2/3;
    } else {

    }
    if (this.hitTestObject(parent1.playerCar)) {
    parent1.playerCar.play();
    parent1._hitAction=true;
    }
    if (parent1._hitAction==true) {
    parent1._speed=0;
    }
    if (this.y>460) {
    parent1._score++;
    //trace(parent1._score)
    this.y=-60;
    switch (Math.round(Math.random()*10)) {
    case 0 :
    this.x=184.6;
    break;

    case 1 :
    this.x=364.6;
    break;

    case 2 :
    this.x=244.6;
    break;

    case 3 :
    this.x=304.6;
    break;

    case 4 :
    this.x=184.6;
    break;

    case 5 :
    this.x=364.6;
    break;

    case 6 :
    this.x=244.6;
    break;

    case 7 :
    this.x=304.6;
    break;

    case 8 :
    this.x=184.6;
    break;

    case 9 :
    this.x=364.6;
    break;
    }
    //184.6 244.6 304.6 364.6
    }
    }
    }
    }
    }
    /////////////////////////////////

    Error received :
    [
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at extramecartrace_fla::MainTimeline/eventStage()
    TypeError: Error #2007: Parameter hitTestObject must be non-null.
    at flash.display:isplayObject/flash.displayisplayObject::_hitTest()
    at flash.display:isplayObject/hitTestObject()
    at AIcar/enterFrameAction()
    ]

  6. #6
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Try replacing this.hitTestObject with event.target. I assume that hitTestObject is on the timeline of the movie extrame car trace.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center