dcsimg
A Flash Developer Resource Site

Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 50

Thread: using XML and movieClips/Objects?

  1. #21
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    ok....I'll have to play with it... havent had tie yet today...hey actually want me to WORK today..instead of "play"..

    Im thinking about an hour...and I'll be able to give her a try...

    been looking into the XML + ComboBox too...I think I'll be able to do that fairly easy as well.. (and will be static for ALL XML nodes created..so I only need it to work once)

    I'll post some code...maybe you an look it over..give some pointers..or corrections if it isnt working.

  2. #22
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    sure. ill help where i can.

  3. #23
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    psst.. me again! (sorry)...LOL

    ok..I have a working model that I understand (wasnt too difficult either)..

    however...how can I get my "attached clips" to NOT be on top of one another? LOL

    (actually I dont think it is attaching multipleClips..I tried to move the firstClip..and there was nothing behind it.).. my code incorrect? maybe the syntax for adding the [i] variable (counter)??...

    Im gettng closer..LOL.. after I can attach as many clips as there are productNodes..

    I can start anew test of populating the combo box using XML... shouldnt be too hard though..I think I can just run through the options and addItem to the comboBox. (but real life application remains to be seen) LOL

    here are the files.....thanks.

    ps. this is the line I added (missing from posted example) to try and move the clips over "X" amount of pixels..everytime one was created:

    code:

    _root.product[i]._x += 200;



    didnt work I had to hard code the target (product1) (which makes me think the [i] counter is working for the attach & naming...


    anyays..anything you can suggest is appreciated.


    update:

    was reading up on the initClip parameter for attachMovieClip... maybe you can help explain better?..the documentation I read was only a few lines..and nothign too graphic. But I am believing this to be the way/method I will populate my "genericClips" when I attach/duplicate them...since all "actions" will be the same for each node/attached Clip only the VALUES will change.

    I also added this:
    code:

    MovieClip.prototype.onRollOver = function() {
    trace(this._name);
    }



    to help me find out what clips have been generated on the stage. (debugging only)
    Attached Files Attached Files

  4. #24
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    first. dont use _root, ever. its a sin.

    when you add or duplicate elements to the stage, you have to set the depth or it defaults to 0 (or 1?). that is the third parameter for the attachMovie method. basically you have to give it an idea of how you want it to be situated in relation to other added clips. you cant attach more than one movie to the same depth or it will just overwrite the previous attached movie. it needs to be incremented in some way. the sequence is usually done something like this:

    Code:
    var obj=this.attachMovie("myClip","myClip"+i,i);
    obj._x=i*200;
    but, another thing to clarify for you is that, in order to achieve the results you were trying to with this:

    Code:
    _root.product[i]._x += 200;
    you would put:

    Code:
    _root["product"+i]._x += 200;
    as you had it, it was looking for objects like _root.product.0, _root.product.1, etc. think of the [] brackets as adding a '.' to the reference and anything within them as the name to the right of the new '.'

    im not sure where you were getting that prototype example from or what it was trying to do. that would just make all clips trace their name when rolling over. generally speaking, using prototypes at all is bad OOP form and is abused far too much. you would do well to simply never use prototypes for anything. granted there are rare exceptions where they provide some good short-cuts and they are worthwhile to understand what they are.

  5. #25
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    code:

    myMovieClip.attachMovie(idName, newName, depth [, initObject] )



    initObject An object containing properties with which to populate the newly attached movie clip. This parameter allows dynamically created movie clips to receive clip parameters. If initObject is not an object, it is ignored. All properties of initObject are copied into the new instance. The properties specified with initObject are available to the constructor function. This parameter is optional.


    sorry that was the parameter I was asking about...(from previous post)


    I have now updated my level parameter to reflect yours.. (not using _root)....can I ask why make it a variable like that? (trying to understand coding practices)


    OH....I just threw that prototype code in there to help me debug when I run the movie... so I "shold" be able to just roll over each of the attached movie clips to see the _name (which should also reflect the xml node (product node) they represent).

  6. #26
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    hmm....talking outloud here..

    I tried:
    code:

    //attachClip Code
    for (i=0; i<totalProducts; i++) {
    var attach = this.attachMovie("templateClip","product"+i,i);
    this["product"+i]._x += 200;
    }



    nothing loads....


    this.....
    code:

    //attachClip Code
    for (i=0; i<totalProducts; i++) {
    var attach = attachMovie("templateClip","product"+i,i);
    this["product"+i]._x += 200;
    }


    loads..but starts in upper left. (_x:0)

    this......
    code:

    //attachClip Code
    for (i=0; i<totalProducts; i++) {
    var attach = attachMovie("templateClip","product"+i,i);
    _root["product"+i]._x += 200;
    }



    loads...and is at X:200


    but I can only see only clip so far..not two....?? hahahahah

  7. #27
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    ic about the initObject. i didnt realize that parameter and had never used it. it might be a good short-cut but its just as well to place the items in separate lines. it might be more clear that way as well.

    using the variable allows for less over-head, meaning you wouldnt have to write the longer _root["blah blah"] several times. it makes the code easier to read and more efficient in some cases since it doesnt need to perform the operations multiple times for the same reference. also, it clearly defines a scope. when you declare a var in a method, class or movieclip, you are limiting the existence of that var to that region of the code. its important to have a good grasp on limiting the scope of variables so that they remain independent of outside systems and potential naming conflicts. its just good practice to only deal with data that you need and to get rid of or "lock up" data that shouldnt be messed with. the larger the project (and team working on) the more valuable that concept becomes.

    the first problem of nothing showing up is probably a scope issue. when i wrote my example i was assuming the code would run in actions on the root timeline so 'this' would refer to the root stage. if you have this code in another movieclip, event function or something, this may refer to somewhere else. for instance, if its in an xml onLoad event, 'this' will refer to the xml object, not the stage. a way to force a good reference to the stage would be to declare a var within the scope of the code. so, if the code is on the root timeline, you would put: var stage:MovieClip=this;

    then you could replace _root or this with stage and have a reference to the stage.

    the reason you can only see one clip is because when you use attachMovie, the new clip is always put at 0,0. the placement code you are using is +=200 which would always be 0 plus 200. use the placement line i gave in previous example( obj._x=i*200 ). that way it will increment the value with each item.

  8. #28
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    I'll have to look into that...but Im not worried as long as the results I desire are the same... more for me doesnt matter as of now..(although later on I would liek to tweak/fine tune the code to be more proficient)

    I have moved on....to:
    a.) populating the comboBox through XML (which I think I sorta have all completed..maybe a quick peep by you?)

    b.) looping through a childNode to get ALL values of sizes to populate the combox with... then move onto the NEXT set of "sizes" nodes..and popluate the next comboBox in the NEXT _parent NODE (product)

    however...now that I have moved the comboBox to be INSIDE my "template" product movieClip.....I can NOT target them..or popluate them...

    I think I am loosing my scope.

    Also couldnt seem to populate te comboBox with nodeVALUES (only returned NULL)...but can do the same exact code except change it to nodeName instead? (which made my xml look a little "weird"

    code:

    //attachClip Code
    for (i=0; i<totalProducts; i++) {
    var attachProduct = attachMovie("templateClip","product"+i,i);
    //placement
    attachProduct._x += i*220;
    //attachProduct._y += i*40;
    attachProduct._y += 40;
    //populate
    for (x=0; x<3; x++) {
    sizeInfo[x] = childs[i].childNodes[3].childNodes[x];
    _root["product"+i].sizeCombo.addItem(sizeInfo[x].nodeName); //doesnt work if the comboBox is being targeted INSIDE the clip
    sizeCombo.addItem(sizeInfo[x].nodeName); //works on _root
    ["sizeCombo"+i].addItem(sizeInfo[x].nodeName); //doesnt work on _root when trying to split up the populating of seperate comboBoxes
    trace(sizeInfo[x].nodeName);
    }
    }



    the 3 lines might look similar.. (read comments)..I was trying different scenario's at once..

    heres the whole .zip file

    www.dmstudios.net/xml_products.zip

    or you want a quick reference:

    whole AS:

    code:

    on (press) {
    myXML_xml = new XML();
    myXML_xml.ignoreWhite = true;

    sizeInfo = new Array();
    colorInfo = new Array();

    myXML_xml.onLoad = getTotalProducts;
    function getTotalProducts(success) {
    if (success == true) {
    rootNode = myXML_xml.firstChild;
    childs = rootNode.childNodes;
    totalProducts = rootNode.childNodes.length;
    trace("Total Products: "+totalProducts);
    trace("XML TREE:"+newline+rootNode.nodeName); //products
    trace(" "+rootNode.firstChild.nodeName); //product0
    trace(" "+rootNode.firstChild.nextSibling.nodeName); //product1
    //trace(" "+rootNode.firstChild.childNodes[0]); //product0
    //trace(" "+rootNode.firstChild.nodeName); //product0
    //trace(" "+rootNode.firstChild.nextSibling.nodeName); //product1

    //attachClip Code
    for (i=0; i<totalProducts; i++) {
    var attachProduct = attachMovie("templateClip","product"+i,i);
    //placement
    attachProduct._x += i*220;
    //attachProduct._y += i*40;
    attachProduct._y += 40;
    //populate
    for (x=0; x<3; x++) {
    sizeInfo[x] = childs[i].childNodes[3].childNodes[x];
    _root["product"+i].sizeCombo.addItem(sizeInfo[x].nodeName); //doesnt work if the comboBox is being targeted INSIDE the clip
    sizeCombo.addItem(sizeInfo[x].nodeName); //works on _root
    ["sizeCombo"+i].addItem(sizeInfo[x].nodeName); //doesnt work on _root when trying to split up the populating of seperate comboBoxes
    trace(sizeInfo[x].nodeName);
    }
    }
    }else {
    trace("Load Failed");
    }
    }
    myXML_xml.load("products.xml");
    }





    whole XML:
    PHP Code:
    <products>

        <
    product0>

            <
    image>image1.jpg</image>

            <
    name>Shirt 1</name>

            <
    price>$19.99</price>

            <
    size>
            <
    small>1 small</small>
            <
    medium>1 medium</medium>
            <
    large>1 large</large>
        </
    size>

            <
    description>etc..etc..etc.</description>        

        </
    product0>

        <
    product1>

            <
    image>image2.jpg</image>

            <
    name>Shirt 2</name>

            <
    price>$24.99</price>

            <
    size>
            <
    x-small>2 x-small</x-small>
            <
    medium>2 medium</medium>
            <
    large>2 large</large>
        </
    size>

            <
    description>etc..etc..etc.</description>        

        </
    product1>

        <
    product2>

            <
    image>image3.jpg</image>

            <
    name>Shirt 3</name>

            <
    price>$34.99</price>

            <
    size>
            <
    small>3 small</small>
            <
    medium>3 medium</medium>
            <
    x-large>3 x-large</x-large>
        </
    size>

            <
    description>etc..etc..etc.</description>        

        </
    product2>

    </
    products

    anything you got is appreciated.

  9. #29
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    i guess i dont see what the question is. except that the comboBox doesnt populate when placed in a different location?

    im just guessing in the dark but its probably because the comboBox isnt completely instantiated yet. if you are attaching it in some way to the screen, many of its functions wont be available until after one frame has ran. i believe macromedia provides a sort of work around for that issue. but, i dont use their components much so im not certain how to use that. in the past, i have worked around it by declaring an onEnterFrame function that runs a populate routine and deletes itself. that way it runs those things once, delayed by 1 frame.

  10. #30
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    yeah..basically through all that..that was my question. I can populate anywhere..except when they are inside the attachedClips...

    I like the onEnterFrame method....but not really sure how I cold incorprate it into what I have going now....without taking it outside of this completely with another object.

    I dont think I can run a variant of it inside my for loop can I? (the nested one)


    what do you think I can search under at MM for a workaround?


    is there anythign I can do to make it ready at runtime?..like linkage properties?? (new to components myself, usually make my own)

  11. #31
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    one approach to be sure it will be ready at the time you want is to attach all components right away in the first frame and control their availability later via _visible. to me, that seems like a clunky way to do it. but, i have seen a lot of ria samples built that way. indeed, even from people/organizations that profess to do things "the right" way. so, it seems to be a legitimate approach.

    i dont like to instantiate things that may not necessarily get used and i dont like things not in use to be in existence. so, i use the onEnterFrame delay approach when i rarely use components or i build my classes to accomodate this situation. here's an example of how i handle this using a little trick with the Delegate class to force the scope of the delayed function to remain local:

    PHP Code:
    //
    //
    //
    // ... code that creates and positions your movieClip containing comboBox ...
    var comboMC this.attachMovie("comboContainer""comboMC"1);
    // ... etc ...
    //
    this.onEnterFrame mx.utils.Delegate.create(this, function ()
    {
        
    //
        // ... code that populates the comboBox ...
        
    comboMC.dataProvider yourXML.firstChild.childNodes;
        
    // ... etc ...
        //
        
    delete this.onEnterFrame;
    });
    //
    // 

  12. #32
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    damn..that was WAY over my head...LOL..

    not really sure if your _visible method will work..as the comboBox's are part of the clip to be attached in the library. So its one package.

    Here is the .zip file... so you can see how my loop then nested loop is set up..


    www.dmstudios.net/test1.zip


    all code is on the button only...the XML file is included....

    the extra comboBox's polluting the stage are just "target" tests... and splitting the data up between multiple box's in a loop. Just cant for the lifeof me get it in the attached clips..LOL

    thanks so far by the way.... I have never used XMl before this.. think Ive come a long way.

  13. #33
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    Ok. I completely revamped the file to bring it closer to how you want to be doing things.

    I made too many changes to go into too much detail about each thing. Try to use it as a guide to learn why different things were done through research.

    But, the glaring things:

    The XML wasn't being put together right. You should never be setting up organization of xml data via sequential naming conventions (product0, product1, etc). one of the main advantages of xml is that new data can be added, removed, moved, etc without messing up some node id scheme. I re-formatted the XML for you.

    You were still using _root and also not declaring objects with var. I did all of that for you. I also added strong typing. You should try and do that as well as much as possible. It can help prevent many types of bugs, typos, etc.

    The loop was a fair amount of code. I broke it up into separate functions to make it more manageable and potentially more re-usable.

    The code was on a button. Dont nest code that way. Always try to at least put the code in the first frame. Even better, learn to use classes so that most of the code isnt in the fla at all. You might be suprised at how little there is to that once you get into it and it will greatly speed up your learning curve for actionscript to do so.

    hope that helps. for reference, here is the new code and xml:

    PHP Code:
    import mx.utils.Delegate;
    //
    //
    //
    var mc:MovieClip this;
    var 
    rootNode:XMLNode;
    var 
    productsNode:Array;
    var 
    totalProducts:Number;
    var 
    myXML_xml = new XML();
    //
    myXML_xml.ignoreWhite true;
    myXML_xml.onLoad Delegate.create(thisgetTotalProducts);
    myXML_xml.load("products.xml");
    //
    //
    //
    function getTotalProducts(success):Void
    {
        if (
    success == true) {
            
    rootNode myXML_xml.firstChild;
            
    productsNode rootNode.childNodes;
            
    totalProducts rootNode.childNodes.length;
            
    createTemplates();
            
    this.onEnterFrame Delegate.create(this, function ()
            {
                
    populateAll();
                
    delete this.onEnterFrame;
            });
        } else {
            
    trace("Load Failed");
        }
    }
    function 
    createTemplates():Void
    {
        for (
    0totalProductsi++) {
            var 
    attachProduct:MovieClip attachMovie("templateClip""product" ii);
            
    attachProduct._x += 220;
            
    attachProduct._y += 40;
        }
    }
    function 
    populateAll():Void
    {
        var 
    i:Number;
        for (
    0totalProductsi++) {
            var 
    xyt:Number;
            for (
    03x++) {
                var 
    size:String productsNode[i].childNodes[3].childNodes[x].nodeName;
                
    sizeCombo.addItem(size);
                
    mc.nested_mc.sizeComboNested.addItem(size);
                
    mc["sizeCombo" i].addItem(size);
                for (
    03t++) {
                    var 
    obj mc["product" t];
                    
    obj.sizeCombo.addItem(size);
                }
            }
            for (
    03y++) {
                var 
    color:String productsNode[i].childNodes[4].childNodes[y].nodeName;
                
    colorCombo.addItem(color);
                
    mc.nested_mc.colorComboNested.addItem(color);
                
    mc["colorCombo" i].addItem(color);
                for (
    03t++) {
                    var 
    obj mc["product" t];
                    
    obj.colorCombo.addItem(color);
                }
            }
        }

    PHP Code:
    <products>
        <
    product>
            <
    image>image1.jpg</image>
            <
    name>Shirt 1</name>
            <
    price>$19.99</price>
            <
    size>
                            <
    small>1 small</small>
                            <
    medium>1 medium</medium>
                            <
    large>1 large</large>
                    </
    size>
                    <
    color>
                            <
    white>white</white>
                            <
    black>black</black>
                            <
    grey>grey</grey>
                    </
    color>
            <
    description>etc..etc..etc.</description>        
        </
    product>
        <
    product>
            <
    image>image2.jpg</image>
            <
    name>Shirt 2</name>
            <
    price>$24.99</price>
            <
    size>
                            <
    x-small>2 x-small</x-small>
                            <
    medium>2 medium</medium>
                            <
    large>2 large</large>
                    </
    size>
                    <
    color>
                            <
    white>white</white>
                            <
    black>black</black>
                            <
    grey>grey</grey>
                    </
    color>
            <
    description>etc..etc..etc.</description>        
        </
    product>
        <
    product>
            <
    image>image3.jpg</image>
            <
    name>Shirt 3</name>
            <
    price>$34.99</price>
            <
    size>
                            <
    small>3 small</small>
                            <
    medium>3 medium</medium>
                            <
    x-large>3 x-large</x-large>
                    </
    size>
                    <
    color>
                            <
    white>white</white>
                            <
    black>black</black>
                            <
    grey>grey</grey>
                    </
    color>
            <
    description>etc..etc..etc.</description>        
        </
    product>
    </
    products

  14. #34
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    WOW....thanks. Alot of this is unfamilar to me..so I do have some question sif ya dont mind??!!

    Yeah I knwo my XML was off alittle..it started off ok...but after doing testing & testing..it "evolved" LOL... so I could grab node name and idetify (in my mind) what child I was in..and know what value to expect..etc..etc..etc.

    I still find myself thinking,.. having the same tag NAME as the VALUE is weird?? why cant I populate the comboBox with the nodeVALUE instead of nodeName? (I read/posted abotu the NULL value return??)

    I was hardCoding fo rthis example...just because it was a test...and I also wont be loading from a button in the final "project"...


    1.) strong typing? like strict typing? (making sure all ase is the same in var names?..etc) or this:
    code:

    rootNode:XMLNode;



    Can you explain more? It looks pretty self explainitory..but is this AS 2.0 convetion? seems liek your just declaring what type of var this is? or will accept? (string, number, XMLNode..etc) but Id like to hear more.

    code:

    function getTotalProducts(success):Void

    whats the VOID part? (not expecting a return?) or what does that do?

    I am using MX..will this matter on any of this? (ahh..i see yoru attachmnt is 2004 or F8)

    It looks as if fr the most part you wrapped the actions in a function and call them..

    the BIGGEST mystery of all is the importing this Delegate class (or whatever it is) I have NO idea what that is.....how to use....or what it does!!.. HAHAHAHA


    I see how you have changed the loops (however they are populating wrong) without using the product+i to loop through the attachedClip and the comboBox's you want to populate, the comboBox's get ALL 9 values instead of just 3 each.

    Im sure can be fixed..but that DELEGATE class?? where can I learn more about it?

  15. #35
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    ok....I hav tried to do EVERYTHING I can that I saw in your (without the importing of some new class (that is totally killing me to understand)...and AS2.0 specifics..and I cant get it to work...NO MATTER WHAT...it is totally JUST abotu that new class that is the trick.. grrr......... (you and you fancy codes) LOL


    but I did tweak your out a little to get the right nodes into the correct comboBoxes...and NOT over populate.. (you have an extra loop in there)

    I have switch ed the code be like this:
    code:

    function populateAll():Void {
    for (i = 0; i < totalProducts; i++) {
    for (x = 0; x < 3; x++) {
    var size:String = productsNode[i].childNodes[3].childNodes[x].nodeName;
    var obj = mc["product" + i];
    obj.sizeCombo.addItem(size);
    }
    for (y = 0; y < 3; y++) {
    var color:String = productsNode[i].childNodes[4].childNodes[y].nodeName;
    var obj = mc["product" + i];
    obj.colorCombo.addItem(color);
    }
    }




    alas..the only thing I really see as differnt is the DELEGATE import class?? what doe sit do???

    Thanks

  16. #36
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    ok..been reading up on the Delegate class.. (still a little fuzzy)..

    but the summary is:

    its just a special wal to call (run) a fucntion inside of any "scope" (timeline/object)

    correct??

    So the missing "link" to my whole problem is:

    a.) Im on MX (although I supose this would be a good reason to make the jump to F8?)
    b.) (MX doesnt have the Delegate class)
    c.) What did they do before MX 2004??? to handle this type of situation? Noone has EVER had a comboBox inside an attached clip that need to be populated?? HAHAHAHA


    I guess I pretty much "understand" your code now.. (took a little time to tace through and evalute it line by line)

    I dont understand the parameters of tis onEnterFrame action though?

    code:

    this.onEnterFrame = Delegate.create(this, function() {
    populateAll();
    delete this.onEnterFrame;
    }
    ); //end Delegate


  17. #37
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    ok.

    strong typing. i may be using the wrong term there. it could be strict typing. but, you were right. i was refering to declaring the var type via :XMLNode, :Number, etc. You should get into the habit of doing that. Once you are used to it you wont notice the extra clicks on the keyboard. But, you WILL notice when the debugger alerts you that you are trying to set a certain type of var to something it cant be. That can really help you debug code and notice mistakes you may have made.

    :Void. you were correct again. you can and should always declare a functions return type for the same reason you declare var types. in fact, i find that function return type conflicts end up helping me debug more often than var types. all of the typing also provides a more readable path for others to follow if they need to work on your code.

    Delegate. sounds like you got it somewhat. its a wrapper that allows you to set the scope of a function. when using AS2 classes it really becomes invaluable because the situation of wanting a foreign even function to run a local function is so common. In this case, it may not have been necessary to be in there, actually. but, lets say that instead of this.onEnterFrame it referenced otherMC.onEnterFrame. without Delegate, it would run the function as if it were inside of otherMC when you most likely would want it to run as if it were in the same scope that you declared the function in. generally, the reason you want it that way is so you can directly access variables. otherwise, you would need a reference path to them which can quickly become messy.

    i dont even remember what version had what any more with flash. are you sure mx didnt have AS2 or delegate yet? you're probably right. i just cant recall.

    anyway, you definitely want to get mx 2004 at least. getting better at AS1 is really like taking a step sideways rather than a step forward. you need to be learning to use classes and AS2 or you will end up re-learning some of the same things twice.

    the onEnterFrame thing was the trick i refered to. its just a way to delay one frame before running a function. the trick aspect is putting a function as a parameter in delegate in order to force the actions of that function to remain local. its not so much of a trick really but it seems like a lot of people dont think to do it. instead, they write another class function and put the name in the delegate command instead, which isnt really necessary.
    Last edited by indivision; 04-08-2006 at 06:16 AM.

  18. #38
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Thanks...I "HAVE been using F8 now..I had it from my job when it came out (same with MX 2004..which I never liked)...and have been using the strict data typeing..(which I dont find cumbersome at all..more repetition to get used to is all... however the fucntion return type is something I have ONLY seen similar to in ASP.net stuff (page states and what not)...so I am not familiar to ANYTHING other than VOID; that one could use..

    Yes..Delegate is only in 7.2 updates and above... thinking of what Delegate lets you do..I was thinking of just trying to put a line of code INSIDE the attachedClip...so when loaded/attached to the stage...it will call the "populate" function I had placed on _root. (still didint work..so I m not if I have a targeting problem..or Im not doing it correctly)

    Is there an AS 2.0 book..like the MX ActionScript book by Colin Moock? (I have Definitive Guide for AS1.0...and it actually helped me learn by leaps anbd bounds)

    yeah the parameters of the Delegate thrw me..was like the other Delegates yo had use , where the parameters were "scope", "function to call".. you used "this", and "funtion"..
    Function I assume was just used (instead of a real function name), becuase you wanted to run the actions in THAT fucntions' parameters???

    Know of any AS 2.0 primers or good reads that can give me some cool tips of AS 2.0 mirgration?

    Thanks for all yoru help so far...(I had some trouble getting the fonts to show up once this .swf was loaded into a target (containerClip)....code didnt seem to be working...but I found how to get to the textField in the compoenent..and change it.

  19. #39
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    The typing for functions isn't any different than for var. If it returns a number, you would put Number where Void is.

    Dont put code inside the attachment clip, especially if it then references back the root. Thats not good OOP since one of the main ideas is to create systems that dont rely on specific references to other systems. Instead, if you want to isolate the code for the attach clip, you build a class and reference that in the linkage properties for the attach clip. When you do that, the code in the class is essentially associated with the root timeline of the clip. About that, in order to link a class to an attach clip the class must extend MovieClip. Perhaps you would be getting ahead of your current understanding to try and do that.

    As a matter of fact, Moock also has a 2.0 book that is widely considered one of the best 2.0 primers for people trying to transition from 1.0. HERE It definitely helped me a lot but I would also like to add that its by no means a complete reference to what you will want to understand for 2.0. Its a great spring-board but leaves quite a few ideas uncovered. Building with classes is quite a departure from the old-school AS1 methods and theres quite a bit of philosophy and debate about various approaches.

    i used delegate there so i could run functions in the scope of the code i instantiated the onEnterFrame function in. in other words, i wanted to access the variables and functions on the screen exactly as i would if i wasnt writing a function on some other object (which would require a longer reference).

  20. #40
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    ok...sohaving code IN the attachedClip (template) is a "no no"....got ya..I understand using _root is NEVER a good idea..and I usually only do so to debug or test..then usually update/twek to be a relative one.

    everything so far is going smoothly...(and Ive learned alot as well..thanks by the way)..also found out how to access the nodeValues instead of just nodeNames (always need firstChild.nodeValue...FYI)..

    but Im trying to go one step further now...and make the image(s) I load into the attachedClip (in its OWN containerClip, called "imageHolder_mc")..and then pass in the link (eventually some javaScript link for a pop-up) for each URL... as follows:

    code:

    var linkVar:String = "http://www.nike.com";
    prodImage_container.onPress = function() {
    getURL(linkVar, _blank);
    }



    I hard coded it for testing..but evetually would like the URL to be passed in another nodeValue as the name, image, rice..etc is.

    Not sure how to go about doing that though? I tried adding it the rest of the code that executes on the Delegate...but nothing...

    I have never written or used a class before this exercise (outside of regular/normal daily FLASH classes)... so classes, accessing them, writing them..etc..is foreign...and DEFINATELY needed.

    I love the AS.10 Language Refernece in the back of Colin Moocks first book.. the whole book was just good learnign for me personally. 2.0 is definately on my list now.

    So..back to the linking problem...any suggestions?...if it is really going to be THAT difficult to pull off...then I might just skip it... (nah, I'll work on it till its done)

    LOL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center