Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 preloader for a swf with document class

Explorer ,
Oct 30, 2011 Oct 30, 2011

Hi,

I have created 1,5mb swf file and I need preloader for it. I don't have any timeline code in it. All written in OOP, based on document class. I grabbed a preloader from my previous projects but this one doesn't work. The output is: "TypeError: Error #1009: Cannot access a property or method of a null object reference at myDocumentClass()"

Basically I want to load large swf in my preloader swf or whatever will work. I tried add loaderInfo to my document class but complete event triggered only when everything is loaded, and nothing appear before that. Just a blank screen.

How to load my large swf with document class into preloader.swf ?

TOPICS
ActionScript
5.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Oct 31, 2011 Oct 31, 2011

Strange that you don't get line numbers in the error when running in debug mode. Try enabling debugging in Publish Settings -> SWF -> Advanced -> Permit debugging.

Another strange thing is that error says "at DocumentlClass()" but your documet class is called "CarouselClass".

Translate
Enthusiast ,
Oct 30, 2011 Oct 30, 2011

That's simple. First of all, you shouldn't put preloader into loaded file itself, because you would have to wait to see the preloader and that kind of misses the whole point of preloading.

You export your 1.5MB file, let's call it loadee.swf.

You need to create another *.fla file, let's call its output loader.swf.

loader.swf:

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgressHandler);

loader.load(new URLRequest("loadee.swf"));

showPreloader();

function loadProgressHandler(event:ProgressEvent):void {

     var percentLoaded:Number = Math.round(event.bytesLoader / event.bytesTotal);

     updatePreloader(percentLoaded);

}

function loadCompleteHandler(event:Event):void {

     loader.contentLoaderInfo.removeEventListener(Event.COMPLETE. loadCompleteHandler);

     loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS);

     addChild(loader.content);

     hidePreloader();

}

function showPreloader():void {

     // show some preloader

}

function updatePreloader(percentLoader:Number):void {

     // show some progress

}

function hidePreloader():void {

     // remove preloader

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 30, 2011 Oct 30, 2011

Peter Celuch: I tried you code and it's still the same: TypeError: Error #1009: Cannot access a property or method of a null object reference.at myDocumentClass() witch is my document class from big swf.

kglad: This is what I did as well. I have tried various options. With this method you talk about I have this output above.

Why preloader.swf need an access to decument class from a big.swf ? I know how to load a swf in diffrent swf but based on timeline. But how to do it with code in document class in big.swf?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2011 Oct 30, 2011

if you know how to create a preloader swf with code on its main timeline, then do that.  you don't have to use a document class in the preloader (or anywhere else).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 30, 2011 Oct 30, 2011

Yeah, I know how to create, but my preloader.swf Cannot access a property or method of a null object reference.at myDocumentClass() in big.swf.

If in big.swf all code will be on timeline, preloader works just fine. But all my code is in document class and preloader cannot accesss that class.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 30, 2011 Oct 30, 2011

The error you described means that you call a property or a method on a variable that points nowhere, equals null. I believe the preloader just started process (as a loading class) that led to instantiation of the loaded swf's Document class. The whole problem is in the "preloader you grabbed from previous project". I believe the code you pasted refers to some preloader object (visual component) on the stage that you forgot to copy to the document. The code chunk should be in your DocumentClass() function (constructor) - delete it, now you have external preloader.

If you experience an error, the best thing to do is to paste it as is without interpretation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2011 Oct 30, 2011

you're probably trying to reference the stage or main timeline in your main swf's document class before that swf is added to the display list.  to remedy, your document class constructor should consist of:

public class WhateverClass(){

// move all the code that used to be in your document class constructor to init()

this.addEventListener(Event.ADDED_TO_STAGE,init);

}

private function init(e:Event):void{

// put here all the code that you had in your constructor

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2011 Oct 30, 2011

if you want a preloader swf to load your large swf, remove your preloader code from your large swf, create a preloader swf and put your preloader code in the preloader swf's document class.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 31, 2011 Oct 31, 2011

kglad: I tried this and it's still the same error. I don't have anything in timeline (no symbols or code). Everything is in ducument class and related as classes. I did init in big.swf and nothing changes.

Peter: But my big.swf works fine without preloader. I don't have anything on stage or timeline. I dont think there is a chance that I forgot any chunk of code. I have checked just to be sure, and there is nothing.

My preloader code in first frame of preloader.swf:

<code>

var request:URLRequest = new URLRequest("big.swf");

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

function loadProgress(event:ProgressEvent):void

{

    var percentLoaded:Number = event.bytesLoaded / event.bytesTotal;

    percentLoaded = Math.round(percentLoaded * 100);

    this.percentLoaded.text = String(uint(percentLoaded)) + "%";

}

function loadComplete(event:Event):void

{

    trace("Load Complete");

}

loader.load(request);

this.addChild(loader);

</code>

trace statement isn't triggered at all.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 31, 2011 Oct 31, 2011

The error pops out before the file is fully loaded thus interrupting code execution - MyDocumentClass() constructor gets called as soon as the loading operation starts (and there's enough bytes to construct the class).

I need you to do 2 things:

1) Run the app with Shitf+Ctrl+Enter so you can paste the exact line number of the error

2) Paste the MyDocumentClass or just it's constructor if you like and mark the error line

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 31, 2011 Oct 31, 2011

Shitf+Ctrl+Enter:

Attempting to launch and connect to Player using URL preloader.swf

[SWF] preloader.swf - 9591 bytes after decompression

[SWF] big.swf - 1785015 bytes after decompression

TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at DocumentlClass()

Cannot display source code at this location.

My document class (simplyfied):

package {

    import flash.display.Sprite;

    import flash.display.MovieClip;

    import flash.events.Event;

    import flash.events.MouseEvent;

    import fl.transitions.Tween;

    import fl.transitions.TweenEvent;

    import fl.transitions.easing.*;

    import flash.events.ProgressEvent;

    public class CarouselClass extends MovieClip {

        

        private vars...

        public function CarouselClass() {

           

            trace("document class triggered");

                this.addEventListener(Event.ADDED_TO_STAGE,init);

         

        }

        private function init(evt:Event):void{

             texts = new Texts();

            carouselSprite = new Sprite();

            addChild(carouselSprite);

            topContainer = new Sprite();

            carouselSprite.addChild(topContainer);

           

            hitBar = new HitBar();

            hitBar.x = stage.stageWidth / 2 - hitBar.width /2;

            hitBar.y = 245;

            addChild(hitBar);

           

            downContent = new DownContent();

            addChild(downContent);

            downContent.y = 325;

            downContent.title_txt.text = "Learning Carousel";

            downContent.description_txt.text = "Click on one of images above to view further details";

            createSections();

        } ... (more functions)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 31, 2011 Oct 31, 2011

Strange that you don't get line numbers in the error when running in debug mode. Try enabling debugging in Publish Settings -> SWF -> Advanced -> Permit debugging.

Another strange thing is that error says "at DocumentlClass()" but your documet class is called "CarouselClass".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 31, 2011 Oct 31, 2011

Oh thank you!

You saved my day. Output gave mi line 16 in my document class. And I had private var center:uint = stage.stageWidth /2 on that line; There was no stage at that time so that coused that problem. Thank you once again.

About names documentClass / CorouselClass - I have chenged names for this forum thopic. Sorry for confuision.

By the way I didn't know about that function Permit debugging. Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 31, 2011 Oct 31, 2011

You're welcome. Enjoy the debug mode

PS: You can debug your applications also when they're already deployed on the server - check this topic: http://forums.adobe.com/message/3998935#3998935

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2011 Oct 31, 2011

how's that possible if you did as i suggested in my message 7 and as shown in your message 10

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 31, 2011 Oct 31, 2011
LATEST

You are right kglad.

I did init funtion but forgot about my vars before doc class added to stage.

I missed what you wrote to me. Thanks for help as well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines