Hi I am new to Flex and AS3 but I have some experience with
XML, XSLT, XPATH, VB etc..
I am having trouble just loading the XML. How do I load an
external XML file so I can edit it?
This is what I have so far:
%26lt;mx:Script%26gt;
%26lt;![CDATA[
var myxml = 'xml/request.xml';
XML.ignoreWhitespace = true;
var xml:XML = new(myxml);
]]%26gt;
%26lt;/mx:Script%26gt;
I recieve an error:
''TypeError: Error #1007: Instantiation attempted on a
non-constructor.''
Thanks in advanceLoad XML and edit
HI!
You have a lot of stuff missing :)
FIrst, the XML Object does not load stuff by itself like
that. You need the URL loader for this
try:
var rq:URLRequest = new URLRequest('xml/request.xml');
var l:URLLoader = new URLLoader(rq);
This will load the XML into your flash movie, even though
you'll have no XML until it's loaded, so you need to add an Event
listener for this:
l.addEventListener(Event.COMPLETE, finishLoading);
Now you need to implement the finishLoading function:
public function finishLoading(evt:Event):void {
var myXML:XML = new XML(evt.target.data);
}
And there you have it :)
Load XML and edit
Thanks for the help. I am a little lost when it come to as3
and FLEX. :)
My code so far is:
%26lt;mx:Script%26gt;
%26lt;![CDATA[
var rq:URLRequest = new URLRequest('xml/request.xml');
var l:URLLoader = new URLLoader(rq);
l.addEventListener(Event.COMPLETE, finishLoading);
public function finishLoading(evt:Event):void {
var myXML:XML = new XML(evt.target.data);
}
]]%26gt;
%26lt;/mx:Script%26gt;
But I recieve these two error...
1120: Access of undefined property finishLoading.
1120: Access of undefined property l.
what is the container for the script tag? is it an
application object?
I am using FLEX 2.
So the Script Tag identifies the content is AS3 not MXML. Any
ideas on how to load and edit?
hmmm I'm kind of confused, if you are not using MXML then
there is no place for the %26lt;mx:SCRIPT%26gt; tag, you should create
a AS3 class that has the code you just showed me, with no tags
anywhere.
if you are using MXML your code should be something like:
%26lt;mx:Application .... (Some more stuff here%26gt;
%26lt;mx:Script%26gt;
..... the code ....
%26lt;/mx:Script%26gt;
%26lt;/mx:Application%26gt;
If you are just using the Script tag you have a problem
:)
use
mx:Script%26gt;
%26gt; %26lt;![CDATA[
%26gt; var myxml = 'xml/request.xml';
%26gt; XML.ignoreWhitespace = true;
%26gt; var xmlobj:XML = new XML;
xmlobj.load(''myxml '');
%26gt; ]]%26gt;
%26gt; %26lt;/mx:Script%26gt;
''XMLmaster'' %26lt;webforumsuser@macromedia.com%26gt; wrote in
message
news:f273l6$ppb$1@forums.macromedia.com...
%26gt; Hi I am new to Flex and AS3 but I have some experience
with XML, XSLT,
%26gt; XPATH,
%26gt; VB etc..
%26gt;
%26gt; I am having trouble just loading the XML. How do I load
an external XML
%26gt; file
%26gt; so I can edit it?
%26gt;
%26gt; This is what I have so far:
%26gt;
%26gt; %26lt;mx:Script%26gt;
%26gt; %26lt;![CDATA[
%26gt; var myxml = 'xml/request.xml';
%26gt; XML.ignoreWhitespace = true;
%26gt; var xml:XML = new(myxml);
%26gt; ]]%26gt;
%26gt; %26lt;/mx:Script%26gt;
%26gt;
%26gt; I recieve an error:
%26gt;
%26gt; ''TypeError: Error #1007: Instantiation attempted on a
non-constructor.''
%26gt;
%26gt; Thanks in advance
%26gt;
hi, i'm having the same issue
my code is in the MXML file, in the ''Script'' tag.
i included flash.net.*;
and keep getting those 4 errors. please help :(
I did that in my application for loading a XML file. I hope
it helps you :)
%26lt;?xml version=''1.0'' encoding=''utf-8''?%26gt;
%26lt;mx:Application
xmlns:mx=''
http://www.adobe.com/2006/mxml''
xmlns:custom=''*''
layout=''absolute''
horizontalScrollPolicy=''off''
backgroundAlpha=''0''
creationComplete=''init();''
%26gt;
%26lt;mx:Script%26gt;
%26lt;![CDATA[
import mx.controls.Image;
import flash.display.*;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
public function init():void
{
var loaderSkin:URLLoader = new URLLoader();
var requestSkin:URLRequest = new URLRequest(''XML/skin.xml'');
loaderSkin.load(requestSkin);
loaderSkin.addEventListener(Event.COMPLETE,
finDuChargementSkin)
}
public function finDuChargementSkin ( event:Event ):void {
var skin:XML = new XML (event.target.data)
\\put your code here
}
]]%26gt;
%26lt;/mx:Script%26gt;
%26lt;mx:Label id=''myLabel'' width=''1000'' fontWeight=''bold''
fontSize=''12''/%26gt;
%26lt;/mx:Application%26gt;
The key is that you cannot do complex assignments outside of
a function because of the way the msml is generated into AS then
compiled into the swf. The declared objects do not exist yet.
Declare the variable in the instance scope, but, as in
Teuzze's example call an init function from the initialize or
creationComplete event, and do the work in there.
Tracy
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment