PDA

View Full Version : to add accordeon elements, from xml lists?


lsag
06-22-2009, 02:01 AM
hi ppl. i'm trying to create an image gallery, with an accordion component. there are several lists to select, and each element is a diferent concert, matching a <coisa> xml element. then update the image list for that concert, and finaly select the image to appear in the third Panel.

so far i've managed to populate the accordion with the xml. that's the code:

<?xml version="1.0" encoding="utf-8"?>
<!-- in
http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&postid=1488&loc=en_US&productid=2
-->

<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml" width="100%"
height="100%" backgroundColor="#FFFFFF" creationComplete="srvLocais.send()" layout="horizontal" viewSourceURL="srcview/index.html">

<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;

[Bindable]
public var xInfo:XML;

public function gereResult(event:ResultEvent):void {
xInfo = event.result as XML;
}
public function verVars(event:Event):void{
trace(event.target);
}
]]>
</mx:Script>

<mx:HTTPService id="srvLocais" url="xml/locais.xml" result="gereResult(event)" resultFormat="e4x" />

<mx:Panel title="locais" width="100%" height="300" autoLayout="true">
<mx:Accordion id="acLocais" width="100%" height="100%" change="verVars(event)">
<mx:Repeater id="repeat" dataProvider="{ xInfo.coisa }" click="verVars(event)" >
<mx:VBox label="{ repeat.currentItem.@txt }" width="100%" height="100%" >
<mx:TextArea width="100%" height="100%" data="{ repeat.currentItem.resumo }"
wordWrap="true" />
</mx:VBox>
</mx:Repeater>
</mx:Accordion>
</mx:Panel>
<mx:Panel title="imgList" id="imgList" width="237" height="300" backgroundColor="#DEDEDE" />
<mx:Panel title="imgXL" id="imgXL" width="237" height="300" backgroundColor="#DEDEDE" />
</mx:Application>

the link: http://www.krig17.com/galeriamar/testes/test09_MXML/testeAcordeao9.html


next i need to update the image list. it is also in xml, and i have a seperate xml for each list.

tried this:

<mx:VBox label="{ repeat.currentItem.@txt }" width="100%" height="100%"
id="{ repeat.currentItem.@id }">
<mx:TextArea width="100%" height="100%" data="{ repeat.currentItem.resumo }"
wordWrap="true" />
</mx:VBox>

after all, "id" is a property of each "coisa" element! and if "repeat.currentItem.@txt" is read, why not "repeat.currentItem.@id"? here is the error:

'{ repeat.currentItem.@id }' is not a valid identifier

realy, don't understand why



so i tried another approach: do it all in actionscript, because i had to give each button an identifier, to get the right xml file. the code:

<?xml version="1.0" encoding="utf-8"?>
<!-- in
http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&postid=1488&loc=en_US&productid=2
-->

<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml" width="100%"
height="551" backgroundColor="#FFFFFF" creationComplete="srvLocais.send()"
layout="vertical" viewSourceURL="srcview/index.html">

<mx:Script>
<![CDATA[
import mx.controls.TextArea;
import mx.containers.Canvas;
import mx.containers.VBox;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;

[Bindable] public var xInfo:XML;

public function gereResult(event:ResultEvent):void {
xInfo = event.result as XML;
//trace(xInfo);
for each(var t:XML in xInfo){
var id:String = t.coisa.@id;
var leg:String = t.coisa.@txt;
var box:VBox = new VBox();
var tArea:TextArea = new TextArea();
box.id = id;
box.label = leg;
box.percentWidth = 100;
box.height = 200;
tArea.percentWidth = 100;
tArea.percentHeight = 100;
box.addChild(tArea);
this.acLocais.addChild(box);
}
}
]]>
</mx:Script>

<mx:HTTPService id="srvLocais" url="xml/locais.xml" result="gereResult(event)" resultFormat="e4x" />
<mx:HBox>


<mx:Panel title="locais" width="300" height="300" autoLayout="true">
<mx:Accordion id="acLocais" width="100%" height="100%" autoLayout="true"/>
</mx:Panel>
<mx:Panel title="imgList" id="imgList" width="237" height="300" backgroundColor="#DEDEDE" />
<mx:Panel title="imgXL" id="imgXL" width="237" height="300" backgroundColor="#DEDEDE" />
</mx:HBox>
</mx:Application>


the link: http://www.krig17.com/galeriamar/testes/test10_AS/testeAcordeao10.html

i do get the variables, but they pilleup on the header of a single accordion element. could someone, please shed some light?

PS: just for completeness, here is the .xml file, in /src/xml/locais.xml:

<?xml version="1.0" encoding="UTF-8"?>
<locais txt="Macão">
<coisa ano="2009" mes="3" dia="24" hora="19" min="05" seg="02" txt="Algés 21.06.09" id="alges_21mar" file="DSC_1487.JPG">
<resumo>resumo de Algés 21.06.09. </resumo>
<id_local>="alges_21mar</id_local>
</coisa>

<coisa ano="2008" mes="11" dia="19" hora="0" min="21" seg="3" txt="Mação" id="macao" file="DSC_1620.JPG">
<resumo>Mação. texto pra encher. texto pra encher. texto pra encher. texto pra encher. texto pra encher.
texto pra encher. texto pra encher. </resumo>
<id_local>macao</id_local>
</coisa>

<coisa ano="2008" mes="11" dia="19" hora="1" min="10" seg="30" txt="Music Box 19.03.2009" id="mbox_19mar2009" file="DSC_1846.JPG">
<resumo>resumo de Music Box 19.03.2009. Music Box 19.03.2009 1. texto pra encher.
texto pra encher. texto pra encher. </resumo>
<id_local>="mbox_19mar2009</id_local>
</coisa>

<coisa ano="2008" mes="11" dia="19" hora="1" min="15" seg="25" txt="Music Box 29.11.2008" id="mbox_29nov2008" file="DSC_1918.JPG">
<resumo>Music Box 29.11.2008. texto pra encher. texto pra encher. texto pra encher.
texto pra encher. texto pra encher. texto pra encher. </resumo>
<id_local>mbox_29nov2008</id_local>
</coisa>

<coisa ano="2008" mes="11" dia="19" hora="2" min="34" seg="40" txt="Santiago Alquimista" id="santiagoAlq" file="DSC_2332.JPG">
<resumo>resumo de Santiago Alquimista. texto pra encher. texto pra encher. texto pra encher.
texto pra encher. texto pra encher. texto pra encher. </resumo>
<id_local>santiagoAlq</id_local>
</coisa>
</locais>