Jump to content
Search Community

Dynamic rawContent

henrye4 test
Moderator Tag

Recommended Posts

Hi, I want assign a number to a clip list by a text field called "numberclip" contained in a external swf.

I call the onLoadSWF function in a "for" cycle to assign an incremental number, but I obtain an Error #1009 and rawContent assigns only the last number.

I don't understand why.

This is my simplified code:

var number = 0;
var ynext = 0;
var clip = new Array("clip01.swf", "clip02.swf", "clip03.swf");
var queue:LoaderMax = new LoaderMax({name:"list"});

for (var i = 0; i < clip.length; i++) {
queue.append( new SWFLoader("swf1/numbered.swf", {name:"numbered",  container:this, x:200, y:ynext, visible:true, autoPlay:true, onComplete:onLoadSWF}) );
number = number +1;
ynext = ynext +40;
queue.append( new SWFLoader("swf1/"+clip[i], {name:"clips", container:this, x:0, y:ynext}) );
}
queue.load();
queue.pause();
queue.resume();

function onLoadSWF(event:LoaderEvent):void {
var A:MovieClip = LoaderMax.getLoader("numbered").rawContent;
A.numberclip.text = number;
}

Can you help me about my error?

Link to comment
Share on other sites

I'm not sure why you were loading the numbered.swf again and again every time through your loop or why you were giving all your loaders exactly the same name, but I think this is what you meant to do:

 

var number = 0;
var ynext = 0;
var clip = new Array("clip01.swf", "clip02.swf", "clip03.swf");
var queue:LoaderMax = new LoaderMax({name:"list"});

for (var i:int = 0; i    number++;
  ynext += 40;
  queue.append( new SWFLoader("swf1/"+clip[i], {name:"clip"+i, number:number, container:this, x:0, y:ynext}) );
}
queue.load();

function onLoadSWF(event:LoaderEvent):void {
  var A:MovieClip = LoaderMax.getLoader("numbered").rawContent;
  A.numberclip.text = event.target.vars.number;
}

Link to comment
Share on other sites

I need to load the numbered.swf as separate item, containing a dynamic number, because clip.length may vary.

Numbered.swf in only a blank swf containing the field, so is very little.

Your solution is valid if clips.swf include the numberclip.text field.

My dubt is that rawContent doesn't match che correct data if the entire queue is not loaded. Is it right?

Link to comment
Share on other sites

My dubt is that rawContent doesn't match che correct data if the entire queue is not loaded. Is it right?

I don't understand your question. Could you explain further?

 

Oh, and feel free to add the "numbered.swf" SWFLoader to the queue outside the loop so that you don't create a bunch of duplicates.

Link to comment
Share on other sites

In my example, I have 3 clips and the loop generates error only on first and second cycle, and correctly insert my number in the last item.

The clip array is dynamically populated, so I don't know in advance how many items need to be numbered.

If I add the numbered.swf outside the loop, it loads only after all clips, at the end of my queue.

I don't love to use the workaround to produce a lot of fixed-numbered swfs and load them with

a code like this, because the number may vary from 1 to n.

queue.append( new SWFLoader("swf1/"+numbered[i], {name:"numbered", container:this, x:0, y:ynext}) );

Thanks again!

Link to comment
Share on other sites

What's the "workaround" you want to avoid? I don't understand why you think I was advocating the use of non-dynamic values. The code I posted was based on an array that could have any number of elements.

 

If you want numbered.swf to load first instead of last, then add it before your loop instead of after.

 

By the way, your code had a flaw:

queue.append( new SWFLoader("swf1/"+numbered[i], {name:"numbered", container:this, x:0, y:ynext}) );

 

You're giving all of your SWFLoaders the same name ("numbered") which won't break anything but it also won't allow you to get them by name via getLoader() or getContent() because there aren't unique names.

 

Did you still have a question?

Link to comment
Share on other sites

Thank you for reply,

obiouvsly I prefer to use dynamic values, and for my app it's mandatory to load, before each clip, an swf containing a progressive number.

If I put the "numbered.swf" before or after the loop, it's loaded only one time, not every time before each clip contained in "clip array".

Imagine to load a certain number of animations (in my case are more than 2.000), and you want to show a progressive number, starting from 1, for each session.

I cannot reopen 2.000 animations and insert a "numberclip.text" field. It's better to load, before each animation, another swf (numbered.swf) which contains the "numberclip.text" field. With rawContent I can access to numberclip.text variable and dynamically populate the progressive number, ever starting from 1.

With static values (but producing 2.000 different swfs with static numbers (e.g. numbered01.swf, numbered02.swf, numbered03.swf, etc)the loop works fine.

The problem is the rawContent access. It matches only the last numbered.swf. Before there is an 1010 error.

I'm sorry if my descripton was not very clear for you. Please, test my source to understand my huge problem.

Thanx

Link to comment
Share on other sites

Please, test my source to understand my huge problem.

I did look at your source - the code I provided fixed the errors. But I didn't realize you wanted to reload the same numbered.swf as many times as there are elements in the clip array. If I understand correctly now, this code should work (I tested it with your source files and it did indeed load numbered.swf and change the text to reflect the number appropriately):

 

var number = 0;
var ynext = 0;
var clip = new Array("clip01.swf", "clip02.swf", "clip03.swf");
var queue:LoaderMax = new LoaderMax({name:"list"});

for (var i:int = 0; i    number++;
  ynext += 40;
  queue.append( new SWFLoader("swf1/numbered.swf", {name:"clip"+i, number:number, container:this, x:0, y:ynext, onComplete:onLoadSWF}) );
}
queue.load();

function onLoadSWF(event:LoaderEvent):void {
  event.target.rawContent.numberclip.text = event.target.vars.number;
}

Link to comment
Share on other sites

WOW, thank you!!

This code version works very fine. My knowledge of LoaderMax is not so good to think a solution like this: name:"clip"+i, number:number.

Now I understand why rawContent macthed only the last value.

Very very good. Solved.

Thank you again

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