PDA

View Full Version : Viewstack help


Urme
05-25-2007, 02:16 PM
Hi I have a Viewstack that looks like this:


<mx:ViewStack id="myViewStack" width="100%" height="100%" x="0" y="47">
<mx:Canvas id="loginUser" label="User Login" width="100%" height="100%">
<ns1:login id="compLogin" horizontalCenter="0" verticalCenter="-28.5">
</ns1:login>
</mx:Canvas>

<mx:Canvas id="start" label="Customer Info" width="100%" height="60%" borderStyle="none">
<ns1:home id="myHome" left="10" right="10" y="10" height="100%">
</ns1:home>
</mx:Canvas>

<mx:Canvas id="admin_users" label="List all users" width="100%" height="60%" borderStyle="none">
<ns1:adm_users id="admusers" left="10" right="10" y="10" height="100%">
</ns1:adm_users>
</mx:Canvas>

<mx:Canvas id="listnews" label="List news" width="100%" height="60%" borderStyle="none">
<ns1:news_list id="newslist" left="10" right="10" y="10" height="100%">
</ns1:news_list>
</mx:Canvas>

<mx:Canvas id="createnews" label="Create News" width="100%" height="60%" borderStyle="none">
<ns1:news_create id="newscreate" left="10" right="10" y="10" height="100%">
</ns1:news_create>
</mx:Canvas>

<mx:Canvas id="editnews" label="Create News" width="100%" height="60%" borderStyle="none">
<ns1:news_edit id="newsedit" left="10" right="10" y="10" height="100%">
</ns1:news_edit>
</mx:Canvas>

<mx:Canvas id="imagesnews" label="Add images" width="100%" height="60%" borderStyle="none">
<ns1:news_images id="newsimages" left="10" right="10" y="10" height="100%">
</ns1:news_images>
</mx:Canvas>

<mx:Canvas id="page4" label="Customer Info" width="100%" height="60%" borderStyle="none">
<mx:Label x="10" y="10" text="Page4" fontSize="17"/>
</mx:Canvas>
</mx:ViewStack>


My problem is that when I for example go to "List news", I load stuff from my mySQL database. With this: initialize="getNews()".
But that only happens the first time I view that page ofc, how can I get that function to run each time I switch to "List news"?

flexy
05-25-2007, 03:18 PM
At the same point in your code where you change your viewStack.selectedChild, do a call to listnews.getNews();

Alternatively, if there going be lots of little calls from changes in your viewstack, use an event.


public function onViewChange(evt:IndexChangedEvent):void
{
if(evt.newIndex == 3)
{
listnews.getNews();
}
}

<mx:ViewStack id="myViewStack" width="100%" height="100%" x="0" y="47" change="onViewChange(event)">

Urme
05-28-2007, 08:26 AM
At the same point in your code where you change your viewStack.selectedChild, do a call to listnews.getNews();

Alternatively, if there going be lots of little calls from changes in your viewstack, use an event.


public function onViewChange(evt:IndexChangedEvent):void
{
if(evt.newIndex == 3)
{
listnews.getNews();
}
}

<mx:ViewStack id="myViewStack" width="100%" height="100%" x="0" y="47" change="onViewChange(event)">


Awesome! Works perfect, thanks!

jsmb
10-14-2007, 06:59 PM
Hello, aaaaaaaaahhh!! I'm looking for an answer to this problem for days now, but this isn't working for me.

I have file A.mxml


<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" >

<mx:Script>
<![CDATA[
import mx.events.MenuEvent;
import mx.controls.Alert;
import mx.collections.*;
import mx.events.ItemClickEvent;
import mx.events.IndexChangedEvent;

private function clickHandler(event:ItemClickEvent):void {
if (event.index==0) {
storeViews.selectedChild = clientenStack;
} else {
storeViews.selectedChild = clientStack;
}
}

private function OnViewChange(evt:IndexChangedEvent):void {
clientenStack.init();
}


]]>
</mx:Script>

<mx:ViewStack id="storeViews" width="100%" height="550" change="OnViewChange(event)">

<clienten id="clientenstack" clientStack="storeViews.selectedChild = clientStack" />

<client id="clientStack"
clientenStack="storeViews.selectedChild = clientenStack" />

</mx:ViewStack>
</mx:Application>


I get this message

call to a possibly undefined method init through a reference with static type canvas

I hope anybody can tell me what i'm doing wrong.