Reading from external file action qustion ....

Posted on 2005-04-19
Medium Priority
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
  • 2
LVL 18

Expert Comment

ID: 13821787
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

ID: 13821841
(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

negatyve earned 2000 total points
ID: 13821941
>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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

864 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