Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6377489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:52:49+00:00 2026-05-25T01:52:49+00:00

i’ve never had to do any cross scripting until now and i’m running into

  • 0

i’ve never had to do any cross scripting until now and i’m running into a (probably really stupid) error right at the start.

External SWF:
i’ve created a new ActionScript 3.0 project in Flash Professional CS5. on the first frame i’ve added the following script:

//Square.fla frame script

import flash.display.Shape;
import flash.events.Event;

var s:Shape = new Shape();
s.graphics.beginFill(0x0000FF, 1.0);
s.graphics.drawRect(-100, -100, 200, 200);
s.graphics.endFill();

s.x = stage.stageWidth / 2;
s.y = stage.stageHeight / 2;

addChild(s);

addEventListener(Event.ENTER_FRAME, enterFrameEventHandler);

function enterFrameEventHandler(evt:Event):void
{
    s.rotation += 2;
}

save, compile, done. this works fine as a stand alone swf, which simply displays a rotating blue square at center stage.

Main SWF:
i’ve created a new ActionScript 3.0 file in Flash Professional CS5, which has a document class called CrossScriptTest:

//CrossScriptTest.as

package
{
//Imports
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.Sprite
import flash.display.Loader;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.events.Event;

//Class
[SWF(width = "1000", height = "500", backgroundColor = "0x444444")]
public class CrossScriptTest extends Sprite
{
    //Constants
    private static const SQUARE_SWF_URL:String = "Square.swf";

    //Variables
    private var SWFLoader:Loader;

    //Constructor
    public function CrossScriptTest()
    {
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;
        stage.frameRate = 60;

        init();
    }

    //Initialize
    private function init():void
    {
        SWFLoader = new Loader();
        SWFLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, IOErrorEventHandler);
        SWFLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteEventHandler);
        SWFLoader.load(new URLRequest(SQUARE_SWF_URL));
    }

    //IOError Event Handler
    private function IOErrorEventHandler(evt:IOErrorEvent):void
    {
        trace(evt);
    }

    //Loader Complete Event Handler
    private function loaderCompleteEventHandler(evt:Event):void
    {
        evt.currentTarget.removeEventListener(IOErrorEvent.IO_ERROR, IOErrorEventHandler);
        evt.currentTarget.removeEventListener(Event.COMPLETE, loaderCompleteEventHandler);

        var squareSWF:Sprite = Sprite(evt.currentTarget.content);
        addChild(squareSWF);
    }
}
}

Error:
i receive the following error:

TypeError: Error #1009: Cannot access a property or method of a null
object reference. at Square_fla::MainTimeline/frame1()

perhaps i’m misunderstanding the nature of cross scripting or loading external swf files, but i can only seem to make this work if i’ve manually drawn display objects on the stage and not if the external swf’s display objects are generated by code.

is it not possible to load external swfs that are programatically created and add them to the display list of a main swf?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:52:50+00:00Added an answer on May 25, 2026 at 1:52 am

    the solution is always so obvious after the fact. the solution is, of course, to assign an Event.ADDED_TO_STAGE event listener in the constructor or initialize method of the external swf’s document class.

    in my defense this was overlooked since it is not required nor common when creating a standard (internal?) document class.

    Main SWF’s Document Class:

    package
    {
        //Imports
        import flash.display.StageScaleMode;
        import flash.display.StageAlign;
        import flash.display.Sprite
        import flash.display.Loader;
        import flash.events.IOErrorEvent;
        import flash.net.URLRequest;
        import flash.events.Event;
    
        //Class
        [SWF(width = "1000", height = "500", backgroundColor = "0x444444")]
        public class CrossScriptTest extends Sprite
        {
            //Constants
            private static const SQUARE_SWF_URL:String = "Square.swf";
    
            //Variables
            private var swfLoader:Loader;
    
            //Constructor
            public function CrossScriptTest()
            {
                stage.scaleMode = StageScaleMode.NO_SCALE;
                stage.align = StageAlign.TOP_LEFT;
                stage.frameRate = 60;
    
                init();
            }
    
            //Initialize
            private function init():void
            {
                swfLoader = new Loader();
                swfLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, IOErrorEventHandler);
                swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteEventHandler);
                swfLoader.load(new URLRequest(SQUARE_SWF_URL));
            }
    
            //IOError Event Handler
            private function IOErrorEventHandler(evt:IOErrorEvent):void
            {
                trace(evt);
            }
    
            //Loader Complete Event Handler
            private function loaderCompleteEventHandler(evt:Event):void
            {
                evt.currentTarget.removeEventListener(IOErrorEvent.IO_ERROR, IOErrorEventHandler);
                evt.currentTarget.removeEventListener(Event.COMPLETE, loaderCompleteEventHandler);
    
                addChild(evt.currentTarget.content);
            }
        }
    }
    

    External SWF’s Document Class:

    package
    {
        //Imports
        import flash.display.Sprite;
        import flash.display.Shape;
        import flash.events.Event;
    
        //Class
        public class Square extends Sprite
        {
            //Constructor
            public function Square()
            {
                init();
            }
    
            //Initialize
            private function init():void
            {
                addEventListener(Event.ADDED_TO_STAGE, addedToStageEventHandler);
            }
    
            //Added To Stage Event Handler
            private function addedToStageEventHandler(evt:Event):void
            {
                removeEventListener(Event.ADDED_TO_STAGE, addedToStageEventHandler);
    
                var s:Shape = new Shape();
                s.graphics.beginFill(0x0000FF, 1.0);
                s.graphics.drawRect(-100, -100, 200, 200);
                s.graphics.endFill();
    
                s.x = stage.stageWidth / 2;
                s.y = stage.stageHeight / 2;
    
                addChild(s);
    
                s.addEventListener(Event.ENTER_FRAME, enterFrameEventHandler);
            }
    
            //Enter Frame Event Handler
            function enterFrameEventHandler(evt:Event):void
            {
                Shape(evt.currentTarget).rotation += 2;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.