The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • ActionScript
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 ActionScript

  • simpelito Author 
    • 6477 
    • 0 
    • 3 
    acccessing vars from parent when loading external swf
    Isocase

    Last reply Jan 13 2009, 08:54 AM

    by Isocase

    Posted: Jul 08 2008, 08:28 AM

    by simpelito

     

Hi all!

I’m missing something crucial here I think…

I’m making a preloader/container swf for a site we’re producing. My idea is to have a generic preloader swf that gets a number of settings from an xml file, saves them all in a Dictionary and then loads an external swf that is used to display the content. A pretty common approach I think, or isn’t it?

The problem though is how do I access variables created in my preloader swf from the externally loaded swf? In AS2 I could just get the vars by starting with _root.whatever but that doesn’t seem to be possible in AS3, right?

  3 REPLIES
 
Nutrox
1  
Nutrox

It is better to call some kind of init method in the loaded SWF file, you can pass the data easily and directly to the loaded SWF that way.

Preloader (parent) code…

package
{
    import flash
.display.Loader;
    
import flash.display.Sprite;
    
import flash.events.Event;
    
import flash.net.URLRequest;

    public class 
ExampleA extends Sprite
    {
        
private var loader:Loader = new Loader();

        public function 
ExampleA()
        
{
            loader
.contentLoaderInfo.addEventListener( Event.INIT, onLoaderInit );
            
loader.load( new URLRequest( "ExampleB.swf" ) );
        
}

        
private function onLoaderInit( e:Event ):void
        {
            Object
( loader.content ).init( "hello" );
        
}
    }
} 

Main (child) code…

package
{
    import flash
.display.Sprite;

    public class 
ExampleB extends Sprite
    {
        
public function ExampleB()
        
{}

        
public function init( param:String ):void
        {
            trace
( param ); // hello
        
}
    }
} 

good

  • 08 July 2008 01:06 PM
  •  
Ecksley
2  
Ecksley

Nutrox,

Bless you.  I’ve been searching for hours for a solution to this problem. This gets the job done. Thank you!

I try to remind myself that smart people seem to think AS3 is a step in the right direction, but God help me… it just isn’t. I defy anyone to explain why all of that init code if more efficient or logical than in AS2 where a child clip would simply say:

trace(_parent.variableInPreloader) 

*head in hands*

  • 13 January 2009 02:07 AM
  •  
Isocase
3  
Isocase

When working with OOP and AS3 you will realize how clean AS3 is compared to AS2. I cringe every time I go back to using AS2 for legacy projects.

  • 13 January 2009 08:54 AM
  •  
  •   Log in or join for free to make a comment.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 775  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,724  Assets
  • Profiles 282,659  Members
  • Topics 93,762  Topics
  • Blog 4  Blog
  • Facebook 1,680  Facebook
  • Twitter 1,165  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 04, 2012 - 18:59:25