Jump to content
Search Community

Document Class and Parent Child Issue

alflasy test
Moderator Tag

Recommended Posts

Hi, I had great time working on my last project with loader max and thanks Carl for all help.

 

Last time it was my first project so I was not messing around with custom classes and all goes well. In this new project I am work with custom document classes where I parent with document class and its loading child swf with XML loader and chlid swf has its own document class.

 

So document class on parent have variables like this as all classes have

public class course extends Sprite {
		
		private var courseXMLLoader:XMLLoader;
		private var courseSWFs;
		private var targetSWFs;

		public static var tests = 'tessssst'
public function course () {
///code here....
}


Now I have succesfully loaded swf and swf has similar class which is trying to get the value of tests. It sound like regular action script and nothing to do with loaderMax. But I can get the var tests when I not using Loadermax but I have issue when I am using loaderMax. So here is the code that fails in child document class

public class slideModual extends Sprite {
		
		
		private var slideXMLLoader:XMLLoader;
		private var menuFormat:TextFormat = new TextFormat();
		private var ansHolder:Sprite;
				
		public function slideModual() {
			
			
		this.addEventListener(Event.ADDED_TO_STAGE, thisAddedToStage )


		}
		private function thisAddedToStage(e:Event){
			trace(Sprite(parent.parent) // Trace - Sprite on parent 
			trace(Sprite(parent.parent).tests) // Trace -  ERROR
			trace(LoaderMax.getLoader("course")); //Trace - LoaderMax 'course'
			trace(LoaderMax.getLoader("course").tests); //Trace -  ERROR
			trace(LoaderMax.getLoader("course").rawContent); //Trace -  ERROR 
		}
			
		}
}

Any Idea please I can easily get it work when these traces on frame but not in document classes.

 

Thank you

Link to comment
Share on other sites

Hi, I'm a little confused. If LoaderMax.getLoader("course") is a LoaderMax, why would it have a rawContent property or a tests property?

 

It almost seems like you should be targeting something that is a SWFLoader or the rawContent of a SWFLoader. Even more odd that all this code works in frame 1 though.

 

If you can boil this down to the absolute smallest number of files to replicate this error, perhaps just 2 swfs and no xml loading, we can definitely investigate further.

Link to comment
Share on other sites

you need to 

 

- make tests a public var (not static) in course.as

public var tests = 'Test Pass';

- in child.as use:

 

private function thisAddedToStage(e:Event){
trace(getXmlName+"____from module")


trace("tests value = " + Object(this.parent.parent.parent).tests);




}

worked for me.

Link to comment
Share on other sites

Thanks Carl, that worked. I tried earlier without static but it didn't worked because I was targeting parent.parent.preant as sprite and not as object. But what about the rawContent? I still can't access it.

 

trace(LoaderMax.getLoader("course").rawContent);//Error
Link to comment
Share on other sites

You are using LoaderMax.getLoader("course") but you create 2 loaders with the name "course" which is bad.

 

in course.as you create an XMLLoader and give it the name "course"

 

courseXMLLoader = new XMLLoader("course.xml", {
//alternateURL:"xmls/working.xml",
name:"course", 
maxConnections:1, 
estimatedBytes:600000, 
//requireWithRoot:this.root,
onInit:courseInitHandler,
//onOpen: moduleXMLLoaderOpen,
onComplete:courseXMLLoaderComplete,
//onProgress:moduleXMLLoaderProgress,
//onChildProgress:imageLoadProgress,
onChildComplete:childLoadComplete
});
 
In your XML file you create a LoaderMax and give it the name "course"
 
<LoaderMax name='course' courseTitle='PERFORMANCE & TALENT MANAGEMENT SYSTEM' >
 
---
 
Depending on where you you use LoaderMax.getContent("course") you will either get a LoaderMax or XMLLoader returned, neither of which have a rawContent property. 
 
Perhaps you want to use someLoaderMax.getChildren() or someLoaderMax.content
 
If you explain what you expect LoaderMax.getLoader("course").rawContent to do we can offer a better solution.
Link to comment
Share on other sites

Wow, that's good to know. I can change the name of course at one place to some thing else.

By getting rawContent I was just trying to have access to course swf so that I have access to all public vars and function which now I know I can still get it by using Object(parent.parent.parent).

 

But its still curiosity why I cant access it by getting rawContent as I use to do it in my last project where I was not using document classes.

Link to comment
Share on other sites

I think you are missing the point that you are targeting the wrong loader. You should pass in the name property of one your SWFLoaders into the getLoader() method. Using "courses" as mentioned above won't work.

 

Typically you can use the URL of the loader but you are loading courses.swf multiple times.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...