PDA

View Full Version : error for basic variable???


luciferonline
09-27-2007, 12:36 PM
Hi there
I have just pick up a project that uses mx components for graphing.
The bad thing is that it uses xml but compiles it rather than links it.

from there I have tried to use the URLloader class and have ran into some weird problems.

var myXML:XML = new XML();
var XML_URL:String = "../assets/data.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoader);
public function xmlLoader(evtObj:Event) :void
{
myXML = XML(myLoader.data);
trace("DATA LOADED");
}


the two items `"myLoader and xmlLoader"'

are undefined. does anybody have some insightful tips for preventing this.

PS: import flexlib.events.*;
import flash.xml.*
import flash.net.URLRequest;
import flash.net.URLLoader;

are all set.
Thanks for any replies

flexy
09-27-2007, 01:13 PM
I see no reference to 'xmlLoader'???

Also, you're not calling the load() method on the URLLoader instance, so it's not calling the server.

Try:

var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener( Event.COMPLETE, xmlLoader );
myLoader.load( myXMLURL );

luciferonline
09-27-2007, 01:58 PM
Cheers for the reply:cool:

the xmlLoader is a function.
Flex is still red lighting it. I am trying to run it locally. might that cause a problem??

its really weird. The rest of the interface is using mx components.
It is telling me that they are undefined properties: but above and below they have been defined.

Is there like a class setting or something that I am missing?????

flexy
09-27-2007, 02:42 PM
Having downloaded your source, I'd certainly spend some time going through adequately scoping your variable declarations. I'm also wondering how you're including this code in your app, as it doesn't have a standard class structure around it??

luciferonline
09-27-2007, 03:15 PM
<mx:Script source="external.as"/>
<mx:Script source="gauge.as"/>
I am using this to include the scripts.
when I link them up. the red light comes on. When I turn them off it disappears.

Is there anything I need to do in the mxml file to allow these vars to be recognised????

If you know of any places with good resources or examples I would be much appreciative.

Cheers:)

flexy
09-27-2007, 03:29 PM
Ahhh, I think you need to rethink how you're architecting your app. Being full OOP, AS3 doesn't take too kindly to code being seemingly 'dumped' into the application. Convert these includes into classes and instantiate them as objects in your application.
Also, it's worth pointing out that whilst you can have multiple script blocks in your MXML document, I'd recommend having only one, for better readability and separation.

luciferonline
09-27-2007, 04:38 PM
this might sound like stupid question but how do you call a class path in flex.
And what would be the best way to handle a xml feed??

luciferonline
09-27-2007, 04:57 PM
so I figured all that out.
now it reckons:

1046: Type was not found or was not a compile-time constant:in Event.
in this function.
function xmlLoader(evtObj:Event) :void


any suggestions??:confused:

luciferonline
09-27-2007, 05:27 PM
Have got a little further. But how do I get the call to the class function to work?

import mx.events.IndexChangedEvent;
import flexlib.events.*;
import flash.xml.*
import flash.net.URLRequest;
import flash.net.URLLoader;
import classes.xml_data_loader;

public var currentIndex:Number = 0;

xml_data_loader.call_XML(true);

This is in the as file.

package classes
{
import flash.display.Sprite;
import flash.xml.*
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
import mx.collections.XMLListCollection;

public class xml_data_loader extends XMLListCollection
{


public function call_XML(bool:Boolean) :void{
if(bool){

trace("LOADDDDDDDDING");
var myXML:XML = new XML();
var XML_URL:String = "../assets/data.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener( Event.COMPLETE, xmlLoader );
myLoader.load( myXMLURL );
function xmlLoader(evtObj:Event) :void
{
myXML = XML(myLoader.data);
trace("DATA LOADED");
}

}
}


}
}

this is the class..


if there is any help going i would be very greatful.

luciferonline
09-27-2007, 05:32 PM
got it working. hey cheers for your help:)