VeyronSA
asked on
Flex Reading Image (that is linked like a banner) from XML to show in Application
Hi,
How can i show a Image with the url linked (like a banner) using XML and mx.Image? I would like to setup banners in my application and get the banner details from the XML file.
Thanks
AJ
How can i show a Image with the url linked (like a banner) using XML and mx.Image? I would like to setup banners in my application and get the banner details from the XML file.
Thanks
AJ
ASKER
Is there any way to get the data from the XML file and show it in mx:Image (not like an slideshow, static images :) ).
Thanks, total noob here
VeyronSA
Thanks, total noob here
VeyronSA
ASKER
Here is my XML file:
What i need is a way to show the details in the XML from my server to the desktop application.
Please show a sample that i can follow :)
<?xml version="1.0" encoding="utf-8"?>
<on_air>
<dj>
<name>Urban Borries</name>
<show>Vivendi Universal</show>
<img>http://www.domain.com/1.png</img>
<blog>http://www.facebook.com</blog>
<email>person@domain.com</email>
</dj>
</on_air>
What i need is a way to show the details in the XML from my server to the desktop application.
Please show a sample that i can follow :)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Petiex,
Thanks for the code :D
However i have a Error:
Description Resource Path Location Type
1008: variable 'pics' has no type declaration. audioPlayer.mxml /Desktop Audio Player/src/com line 59 Flex Problem
Any idea?
Thanks
Thanks for the code :D
However i have a Error:
Description Resource Path Location Type
1008: variable 'pics' has no type declaration. audioPlayer.mxml /Desktop Audio Player/src/com line 59 Flex Problem
Any idea?
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks :D
ASKER
Just a quick question, is there a way that the application can refresh the data every hour or so?
Yes. You could set a timer to call loadXML() at whatever interval.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" percentHeight="100" percentWidth="100"
creationComplete="setTimer()"
>
<mx:Script><![CDATA[
private var myXML:XML;
//You will want to make this much larger. I have it at 20 seconds
//for testing.
private const intervalInMilliseconds:Number = 20000;
private function setTimer():void{
loadXML(null);
var timer:Timer = new Timer(intervalInMilliseconds,0);
timer.addEventListener(TimerEvent.TIMER, loadXML);
timer.start();
}
private function loadXML(event:Event):void {
//add new date querystring to avoid browser caching
var loader:URLLoader = new URLLoader(new URLRequest("http://localhost:9080/test.xml?v="+(new Date()).getTime()));
loader.addEventListener(Event.COMPLETE, loadComplete);
}
private function loadComplete(event:Event):void{
myXML = new XML(event.target.data);
myImage.source = myXML.dj.img;
myImage.addEventListener(MouseEvent.CLICK, openLink);
}
private function openLink(event:MouseEvent):void{
navigateToURL(new URLRequest(myXML.dj.blog))
}
]]></mx:Script>
<mx:Image id="myImage" useHandCursor="true" buttonMode="true"/>
</mx:Application>
By the way, I posted a possible answer for another of your questions last week, if you would like to have a look:
https://www.experts-exchange.com/questions/26630815/Flash-Flex-change-xml-data-according-to-time.html
https://www.experts-exchange.com/questions/26630815/Flash-Flex-change-xml-data-according-to-time.html
ASKER
Hi Petiex,
Just 1 more question, i want to add another link for the email when clicking on a icon, is there a way that the script can see the difference between the blog and email link?
Thanks from a super Noob :D
Just 1 more question, i want to add another link for the email when clicking on a icon, is there a way that the script can see the difference between the blog and email link?
Thanks from a super Noob :D
If you add an mx:Image with id="emailIcon" in the mxml, then you can make it an email link by modifying your code like this (lines commented with //+ indicate added code):
private function loadComplete(event:Event): void{
myXML = new XML(event.target.data);
myImage.source = myXML.dj.img;
myImage.addEventListener(M ouseEvent. CLICK, openLink);
emailIcon.addEventListener (MouseEven t.CLICK, openEmail); //+
}
private function openLink(event:MouseEvent) :void{
navigateToURL(new URLRequest(myXML.dj.blog)) ;
}
private function openEmail(event:MouseEvent ):void{ //+
navigateToURL(new URLRequest("mailto:"+myXML .dj.email) ); // +
} // +
private function loadComplete(event:Event):
myXML = new XML(event.target.data);
myImage.source = myXML.dj.img;
myImage.addEventListener(M
emailIcon.addEventListener
}
private function openLink(event:MouseEvent)
navigateToURL(new URLRequest(myXML.dj.blog))
}
private function openEmail(event:MouseEvent
navigateToURL(new URLRequest("mailto:"+myXML
} // +
http://www.riacodes.com/flex/build-a-xml-image-viewer-in-flex/