Avatar of acekz
acekzFlag for United States of America

asked on 

Flash onData vs. onLoad

Why should I use the onData method over the onLoad method when using .loadVars or vice versa? They both look the same almost, i just want to make sure I don't do anything until all my data is sent back to me.
Adobe Flash

Avatar of undefined
Last Comment
acekz
ASKER CERTIFIED SOLUTION
Avatar of ivan_os
ivan_os

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ivan_os
ivan_os

Hmm,
I think I forgot to answer your question.

You should use onLoad method when you're expecting name-value pairs of data, because they will be automatically converted to properties so you can comfortably use them. Example:
---
data.txt:
name=John&age=35&city=New York
---
var myLoadVars = new LoadVars();
myLoadVars.onLoad = function (success)
{
    if(success)
    {
        //here you have access to all data converted to properties of myLoadVars object
        //so myLoadVars has from now on "name", "age" and "city" prop. and you can use their
        //values:
        trace(this.name);
        trace(this.age);
        trace(this.city);
    }
}
myLoadVars.load("data.txt");
-----

You should use onData method when you're expecting other than name-value pairs encoded data, for example some raw text, article ...  Example:
---
data.txt:
This is great article about ActionScript. It's great. Blah blah...
---
var myLoadVars = new LoadVars();
myLoadVars.onData = function (src:String)
{
    //src parameter contains loaded data
   trace(src); // this will trace out: "This is great article about ActionScript. It's great. Blah blah..."
   // so you can assign it as is to some TextField
   _root.article_TextField.text = src;
}
myLoadVars.load("data.txt");
-----

I hope it's clear now.

Regards,
ivan_os
Avatar of acekz
acekz
Flag of United States of America image

ASKER

ivan,

Thank you very much for your concise and accurate explanation! I have used both methods many times before, but never really figured out why! go figure...Anyway, I do understand better now and gladly award you all the points. Thanks again!
Adobe Flash
Adobe Flash

Adobe Flash (formerly Macromedia Flash) is a cross-platform multimedia and software platform used to embed animations, video, and interactive applications into web pages and desktop and mobile applications and games. Flash displays text, vector and raster graphics to provide animations, video games and applications. It allows streaming of audio and video, and can capture mouse, keyboard, microphone and camera input. The ActionScript programming language allows creation of interactive animations, video games, web applications, desktop applications and mobile applications.

29K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo