+ Reply to Thread
Results 1 to 5 of 5

Thread: actionscript + XML

  1. #1
    rvr1982 is offline x10Hosting Member rvr1982 is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    3

    actionscript + XML

    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 Code:
    <?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

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: actionscript + XML

    Quote Originally Posted by rvr1982 View Post
    first of all, I'm using Flash CS4, and Actionscript2.0.
    Too bad you aren't using AS3. E4X is so nice.

    Quote Originally Posted by rvr1982 View Post
    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.

    Quote Originally Posted by rvr1982 View Post
    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".
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    rvr1982 is offline x10Hosting Member rvr1982 is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    3

    Re: actionscript + XML

    OMG ! i hate these "_root", "parent" ant "this", really ! :x

    Thanks sooo much, it works now ;)

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: actionscript + XML

    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 by misson; 10-14-2009 at 04:14 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    rvr1982 is offline x10Hosting Member rvr1982 is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    3

    Re: actionscript + XML

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

+ Reply to Thread

Similar Threads

  1. Actionscript: avoid loading the same file twice
    By thotalg in forum Programming Help
    Replies: 4
    Last Post: 02-16-2009, 02:27 PM
  2. I need help with actionscript 3.0
    By sdc151 in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 05-06-2008, 12:29 PM
  3. ActionScript relating to XML
    By diabolo in forum Programming Help
    Replies: 0
    Last Post: 01-13-2008, 06:54 AM
  4. Flash, XML, and ActionScript
    By diabolo in forum Programming Help
    Replies: 1
    Last Post: 01-08-2008, 08:30 PM
  5. PHP - Actionscript
    By manila in forum Introductions
    Replies: 1
    Last Post: 12-25-2007, 01:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers