A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Loader child swf stage resize issue

  1. #1
    Member
    Join Date
    Aug 2004
    Location
    Toronto, Ontario, Canada
    Posts
    50

    Loader child swf stage resize issue

    Hi there,

    I've exhausted Google for answers, so I'm turning to the pros...

    Basically I have a loader in Main.swf and I'm loading Index.swf into it then setting the loader width/height to the full size of the users stage.

    Within Index.swf I am now trying to set items on the stage according to the width/height. I've written the code to do the positioning but when I run Main.swf it throws:

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

    What I'm wondering is...how the heck can I pass the parents stage dimensions? Second of all, if the stage resizes, how am I going to fix the position of the elements in the child?

    I was thinking of two ways, but don't quite know how to do it...the first is to pass data via the loader, but where would I pick that data up in the child? Second of all using LocalConnection...but I only know how to call functions...does that mean I have to create a function in the child to receive the new dims?

    Help? :-)
    ---
    David Di Biase

  2. #2
    Senior Member Kirill M.'s Avatar
    Join Date
    May 2002
    Location
    Toronto, Canada
    Posts
    711
    What makes you think it's a problem with resizing? Flash was nice enough to tell you what the actual problem is (which from the error message is not a resize issue) and I'm sure it also told you the line number at which the problem occurred. You should take a look at what's happening there.

  3. #3
    Member
    Join Date
    Aug 2004
    Location
    Toronto, Ontario, Canada
    Posts
    50
    Well actually it doesn't tell me the line, but I was able to track it down to these line:

    stage.addEventListener(Event.ADDED, this.onStageResize);
    stage.addEventListener(Event.RESIZE, this.onStageResize);

    Obviously the code is correct because it works when I run Index.swf separately.

    Jeeze don't have to be so smug about it :-p I'd still appreciate a suggestion though.
    ---
    David Di Biase

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Why do you add "this" to the function? The stage of a loaded movie will automatically become the stage of the parent.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Member
    Join Date
    Aug 2004
    Location
    Toronto, Ontario, Canada
    Posts
    50
    The event should be calling the current class function to detect if the stage has been modified at all, that's why this. is being called.

    Take a look at my source, which I zipped and attached. Main.as is my DocClass for Main.swf and Index.as for Index.swf.

    That should give you a better idea...
    Attached Files Attached Files
    ---
    David Di Biase

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Just as a rule try keeping the constructor empty except for the Doc class and make separate function, which you call once the movie is loaded. You should do traces to see what is null in the index movie. My guess is it may be stage in the constructor. Also you don't need to write "this" any more. In AS3 any property or function if not otherwise defined will automatically refer to the class. It makes coding easier and reduces code.

    Since I cannot reproduce the movie I can only guess.
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Member
    Join Date
    Aug 2004
    Location
    Toronto, Ontario, Canada
    Posts
    50
    Cool, I didn't know that I could live this out :-) heh. It does seem like it's the stage object, if that's the case what should I do to fix it?
    ---
    David Di Biase

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Place the stage function in a separate function, which you call when the movie is loaded.
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    Member
    Join Date
    Aug 2004
    Location
    Toronto, Ontario, Canada
    Posts
    50
    The question is how the heck do I call it AFTER the constructor is called. My initial thoughts are...use an Event and somehow have it trigger it onComplete, but how do I add an event for the current swf?... lol
    ---
    David Di Biase

  10. #10
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    In Main.as

    public function resize_loadedSwf(e:Event) {
    e.currentTarget.content.sResize();
    e.currentTarget.scaleMode = "noScale";
    e.currentTarget.content.width = stage.stageWidth;
    e.currentTarget.content.height = stage.stageHeight;
    }

    in Index.as

    public function sResize():void
    {
    stage.addEventListener(Event.RESIZE, onStageResize);
    }


    I am not sure it is working, since I cannot test it.
    - The right of the People to create Flash movies shall not be infringed. -

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