Jump to content
Search Community

setting name of loaded swf

Eckstein1 test
Moderator Tag

Recommended Posts

Hi,

I want to set the name of a loaded MovieClip. The code attached shows what I want to do. It's not the one I'm using (only used to explain what I try to do).

 

import flash.display.MovieClip;
import flash.events.*;

import com.greensock.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.*;

var myName:String = "Movie";
this[myName] = new MovieClip();
this[myName].name = myName;

var loader:SWFLoader = new SWFLoader("movies/main.swf", {name:"example", container:this, onComplete:completeHandler});
loader.load();

function completeHandler(event:LoaderEvent):void {
trace(this[myName].name);				// Movie
trace(event.target.rawContent.name);	// instance4
//event.target.rawContent.name = myName;	// Error: Error #2078: ...
this[myName]=event.target.rawContent;
trace(this[myName].name);				// instance4
trace(event.target.rawContent.name);	// instance4
//this[myName].name = myName;				// Error: Error #2078: ...
}

 

What do I have to do to set the name and keep the name?

Thanks a lot in advance

Uli

Link to comment
Share on other sites

Flash will not allow you to change the name of the root of a swf like that. It has nothing to do with LoaderMax. You can, however, change the name of the ContentDisplay Sprite that wraps the rawContent. By default, it is given the same name as the loader itself, but you can change it if you prefer. Do you mind me asking why you're trying to change the name like that anyway? What purpose does it serve? And why not use the ContentDisplay instead?

 

function completeHandler(event:LoaderEvent):void {
   event.target.content.name = "whatever";
}

Link to comment
Share on other sites

Hi again,

 

if I understand it correctly there is the following difference between content and rawContent:

content: container integrating the loaded swf (rawContent) as a sub-object (name like loader object)

rawContent: the loaded swf itself without a container integrating it (name "instance..." whatever)

 

What I'm working on is a tool similar to your XMLLoader which receives a xml structure and generates loadings out of it.

What I'm developing is a tool receiving a xml-file and generating tweens, timelines and actions (i.e. MOVIE1.visible=true, MOVIE2.mouseLeave=MOVIE2.x+200, MOVIE3.background.color=0, etc) out of it.

 

To implement the actions quite simple I use the instance names to access the objects. I could implement a code which routes the action if required to the rawContent, but I try to avoid that.

 

Would it be possible for you to add a parameter to set the name of the rawContent (i.e. rawName="MOVIE")?

 

If I read the error message correctly it says that the object is already added to the DisplayList. Maybe you could add a parameter (i.e. addDisplayList=false) to prevent adding it to the DisplayList or is there any way to remove it from the DisplayList, set the name and add it to the DisplayList again?

 

Thanks a lot for your great support

Uli

Link to comment
Share on other sites

if I understand it correctly there is the following difference between content and rawContent:

content: container integrating the loaded swf (rawContent) as a sub-object (name like loader object)

rawContent: the loaded swf itself without a container integrating it (name "instance..." whatever)

Yep, that's correct.

 

Would it be possible for you to add a parameter to set the name of the rawContent (i.e. rawName="MOVIE")?

 

If I read the error message correctly it says that the object is already added to the DisplayList. Maybe you could add a parameter (i.e. addDisplayList=false) to prevent adding it to the DisplayList or is there any way to remove it from the DisplayList, set the name and add it to the DisplayList again?

Nope, the issue has nothing to do with whether or not the object is in the display list. You can change the name property of DisplayObjects regardless of whether or not they're in the display list. However, apparently Flash will NOT allow you to change the name of the root of a swf. For example, this throws an error:

this.root.name = "test";

So to answer your question, no, I cannot add a special rawName property like that. Sorry. It doesn't help to take the object out of the display list and try editing the name either.

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...