Reading from external file action qustion ....

Posted on 2005-04-19
Last Modified: 2010-04-03
Hi experts

in this example flash read more than one record from external text file with this code ..

        myData = new LoadVars()
        myData.ref = this
        myData.onLoad = function(succes){
                for(var i=0; i<this.cant; i++){
                    this.ref["Title_txt"+i].htmlText = "<b>"+this["Title"+i]+"</b>"
                    this.ref["Comments_txt"+i].text = this["Comments"+i]
            } else trace("Error loading data")

my quistuin is
What is " ref " and we use it many times in the code
can any body explain the example ???

Question by:FLAASHER
    LVL 18

    Expert Comment

    from the tutorial I would say you could just as easily replace 'ref' with _root, and get rid of the 'this'
    does this sample actually work? I noticed success is spelled wrong in it...


    LVL 18

    Expert Comment

    (as in the first example).
    Because, the textifelds are on the _root timeline there, as is the loadVars script.
    So you don't really need it, but it is a method to give you the current timeline, no matter where youa re working.
    Does this make sense?

    LVL 27

    Accepted Solution

    >What is " ref " and we use it many times in the code

    "ref" is a reference to the timeline holding script and textfields. It's used because, from inside the onLoad function, the "this" keyword refers to the LoadVars instance itself, not to the timeline, and, to address the holding timeline, you cannot use "_parent", because "_parent" its a MovieClip Class property, not LoadVars.

    That's why in that script you create a hard coded reference to the timeline inside the LoadVars instance, and use "this.ref" as a shortcut.
    A more aelegant way of write it is:

            // just create a temporary variable with a reference to the timeline
            // don't write it in the LoadVars instance
            var reference = this;
            var myData = new LoadVars()
            myData.onLoad = function(succes)
                    for(var i=0; i<this.cant; i++){
                        // use it without "this": the function can still access it
                        // and you didn't write the property to the instance
                        reference["Title_txt"+i].htmlText = "<b>"+this["Title"+i]+"</b>"
                        reference["Comments_txt"+i].text = this["Comments"+i]
                } else trace("Error loading data")

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
    I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
    The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
    The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now