actionscript + XML

rvr1982

New Member
Messages
3
Reaction score
0
Points
0
first of all, I'm using Flash CS4, and Actionscript2.0. Here's the website : rvr3d.pcriot.com

There are just 2 parts that are working right now, the "stills" section, and the "SMC" section. I'm currently working on the "animation" section.

I try to use the same template as for the other two working sections, except that i'm now showing FLV files, not images.

In my XML file, i have this

HTML:
<?xml version="1.0" encoding="utf-8"?>
<gallery heading="SMC">
<piece>
    <heading>title01</heading>
    <desc>description01</desc>
    <image>anim01</image>
</piece>
<piece>
    <heading>title02</heading>
    <desc>description02</desc>
    <image>anim02</image>
</piece>
<piece>
    <heading>title03</heading>
    <desc>description03</desc>
    <image>anim03</image>
</piece>
</gallery>
I'm using the name in the "image" tag to find both the thumbnails (anim01.jpg), and the animation (anim01.flv). The only difference is the folder where flash is going to look at them.

Now the problem :
The thumbnails are loading correctly, but not the videos. In this case, i have 3 "piece" tags, the displayed FLV is always the last one (anim03.flv in this case). It worked well with images in the other sections of my website, but not here anymore, so i might have made something wrong in my actionscript.

For the images in the working sections, i used this code, and it works fine :
Code:
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(ok) {
    if (ok) {
        allGalleryData = this.firstChild.childNodes;
        for (i=0; i<allGalleryData.length; i++) {
            
// ----> this is the part that i'm going to change for the FLV's to display instead of the images

            newPiece = sliderHolder_mc.slider_mc.attachMovie('template', 'piece'+i, i);
            newPiece._x = i*newPiece._width;
            newPiece.heading_txt.text = allGalleryData[i].firstChild.firstChild; 
            newPiece.desc_txt.text = allGalleryData[i].firstChild.nextSibling.firstChild; 
            newPiece.load_btn.imageName = allGalleryData[i].firstChild.nextSibling.nextSibling.firstChild;
            newPiece.holder_mc.loadMovie('thumbs/'+newPiece.load_btn.imageName);
            newPiece.load_btn.onRelease = function() {
                loadNewImage('images/'+this.imageName);
                globalContent_mc._visible=false;
                trace('images/'+this.imageName);

// ----> end of the part i'm changing for the FLV's to load

            };
            newBut = attachMovie('numTemplate', 'num'+i, i);
            newBut._y = -2;
            newBut._x = (i*27)+sliderHolder_mc._x;
            newBut.myNum = i;
            newBut.num_txt.text = i+1;
            newBut.onRelease = function() {
                targX = 0-(this.myNum*133);
            };
        }
        targX = 0;
        sliderHolder_mc.slider_mc.onEnterFrame = function() {
            this._x -= (this._x-targX)/5;
        };
    } else {
        trace('what file?');
    }
};
myXML.load('xml/Stills.xml');

note : the trace i put after the button's onrelease function works well right now !

Now, the same wit the FLV's instead of the Images :
Code:
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(ok) {
    if (ok) {
        allGalleryData = this.firstChild.childNodes;
        for (i=0; i<allGalleryData.length; i++) {
            newPiece = sliderHolder_mc.slider_mc.attachMovie('template', 'piece'+i, i);
            newPiece._x = i*newPiece._width;
            newPiece.heading_txt.text = allGalleryData[i].firstChild.firstChild;
            newPiece.desc_txt.text = allGalleryData[i].firstChild.nextSibling.firstChild;
            newPiece.load_btn.imageName = allGalleryData[i].firstChild.nextSibling.nextSibling.firstChild;
            newPiece.holder_mc.loadMovie('thumbs/'+newPiece.load_btn.imageName+'.jpg');

// -----> here i introduce the variable that allows me to load FLV's

            var nc:NetConnection = new NetConnection();
            nc.connect(null);
            var ns:NetStream = new NetStream(nc);

// -----> theVideo is the instance name of a New Video container from the library

            theVideo.attachVideo(ns);

// -----> from now on, flash will always consider that i = last piece of my XML file ! ... but why ? 

            newPiece.load_btn.onRelease = function() {
                ns.play('animation/'+newPiece.load_btn.imageName+'.flv');
                globalContent_mc._visible=false;
                trace('animation/'+newPiece.load_btn.imageName+'.flv');
            };

// ------> the rest has not changed, so i did not copied it again

When I trace the flv, i always get the one of the last piece of my XML file, in this example it's anim03.flv
Why does it work with images, but not with FLV's ?
I think i must have done something wrong in my code, but what ?
It's the very last error i have on my website, i've tried to get some help on "actionscript.org", but no one could help me.

Any hint, solution or other helpfull advise will be very much appreciated ;)

Cheers,

rvr
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
first of all, I'm using Flash CS4, and Actionscript2.0.
Too bad you aren't using AS3. E4X is so nice.

For the images in the working sections, i used this code, and it works fine :
Code:
            newPiece.load_btn.onRelease = function() {
                loadNewImage('images/'+this.imageName);
                globalContent_mc._visible=false;
                trace('images/'+this.imageName);
            };
Here you're pulling imageName from this, which has local scope.

Now, the same wit the FLV's instead of the Images :
Code:
            newPiece.load_btn.onRelease = function() {
                ns.play('animation/'+newPiece.load_btn.imageName+'.flv');
                globalContent_mc._visible=false;
                trace('animation/'+newPiece.load_btn.imageName+'.flv');
            };
Here you're pulling imageName from newPiece, which is from the containing scope. The onRelease handler runs after the for loop has finished, at which point newPiece refers to the last thumbnail button you created, piece3. Change "newPiece.load_btn" to "this".
 

rvr1982

New Member
Messages
3
Reaction score
0
Points
0
OMG ! i hate these "_root", "parent" ant "this", really ! :x

Thanks sooo much, it works now ;)
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I could be wrong, but doesn't CS4 support AS3? It has features that can improve readability and make some tasks easier. For instance E4X can be simpler than the W3C DOM.
Code:
myXML.onLoad = function(ok) {
    if (ok) {
        for each (var piece in this.piece) {
            newPiece = sliderHolder_mc.slider_mc.attachMovie('template', 'piece'+i, i);
            newPiece._x = i*newPiece._width;
            newPiece.heading_txt.text = piece.heading.text();
            newPiece.desc_txt.text = piece.desc.text(); 
            newPiece.load_btn.imageName = piece.image.text();
            // ...
 
Last edited:

rvr1982

New Member
Messages
3
Reaction score
0
Points
0
You're right...

But I started Flash without knowing anything about it, it's been something like 4-5 weeks I work on this website...
When I started, I just followed instructions in a tutorial. The guy said "use AS2.0", so I picked AS2.0 ^^

Now I'm kind of afraid of what could go wrong if i change. And I think this FLV loading thing was the last real complicated thing i had to script, so I wont really need much Actionscript anymore.

For the next website I'll create (if there'll be any), I'll probably chose directly AS3.0 ^^
 
Top