问题
I am having an issue with using the SplitViewNavigator component in flex 4.6 using Adobe Flash Builder.
[UPDATED]* * *
I am building a reddit app for the blackberry playbook tablet, and am making use of reddit's API. I have three mxml views: RedditReaderHomeView.mxml, redditFeed.mxml, and subredditList.mxml. In RedditReaderHomeView.mxml I have a splitViewNavigator. In left side of my SplitViewNavigator resides subredditList.mxml, and on the right side resides redditFeed.mxml. On initialization, redditFeed.mxml pulls in XML data to populate its list with reddit entries, and subredditList.mxml pulls in XML data which populates its list with subreddits(categories) to display. When a user clicks on of the subreddit entries on the left, the redditFeed.mxml on the right should update so that the data it pulls are entries from the subreddit category that was selected on the left. In other words, classic master/detail navigation. Category on the left, which opens entries of that category on the right.
Well, I have a function that passes the url of the selected subreddit over to redditFeed.mxml.
subredditList.mxml - here a subreddit is selected and its url is sent over to a function in redditFeed.mxml
public function list_clickHandler(event:IndexChangeEvent):void {
var RSSItem:Object = redditList.dataProvider.getItemAt(event.newIndex);
var thisItem:Item = RSSItem as Item;
rlink = thisItem.link;
var moddedLink:String = rlink.slice(1, int.MAX_VALUE)
var pushSub:redditFeed = new redditFeed();
pushSub.myList_creationCompleteHandler(moddedLink);
}
redditFeed.mxml - the url is used to grab data from that particular subreddit...
public function myList_creationCompleteHandler(url:String):void
{
getRedditFeedResult.token = redditFeedGrabber.getRedditFeed(url);
}
... though this data never seems to be displayed in the spark List component, even though I can see the call being made through the Network Monitor. I've spent hours and hours trying to solve this. And I belive it has something to do with views being 'active' vs. 'deactivated', as when i tried placing this same call from within redditFeed.mxml, the call went through and the data in the list updated. I thought perhaps this was because the action was being performed within the same view that contains the list where the data is displayed. So it would be 'active' in this instance as the action is being performed in that view.
I appreciate any help anyone can offer. Also, dont hesitate to request clarification/more details from me. I reeeallly want to solve this. Thanks!
RedditReaderHomeView.mxml - Here's the code you requested. Lemme know if you need more/something else.
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
actionBarVisible="false" tabBarVisible="true" title="Reddit Reader by Domisy" creationPolicy="all"
actionBarVisible.landscape="true">
<fx:Script>
<![CDATA[
import com.adobe.fiber.core.model_public;
import mx.events.FlexEvent;
import views.redditFeed;
public var defUrl:String = new String("");
public function refreshRSS(event:Event):void
{
//***UPDATED CODE****
var refreshFunction:Object = redditFeedNav.getElementAt(0);
refreshFunction.refreshList();
//var refreshFunction:redditFeed = new redditFeed();
//refreshFunction.refreshList();
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:states>
<s:State name="portrait"/>
<s:State name="landscape"/>
</s:states>
<s:actionContent>
<s:Button includeIn="landscape" click="navigator.pushView(profileView)"
icon="@Embed('assets/images/profileIcon.png')"/>
</s:actionContent>
<s:SplitViewNavigator width="100%" height="100%" id="splitViewNavigator" autoHideFirstViewNavigator="true">
<s:ViewNavigator id="redditListNav" firstView="views.subredditList" width="300" height="100%"/>
<s:ViewNavigator id="redditFeedNav" firstView="views.redditFeed" width="100%" height="100%">
<s:actionContent.landscape>
<s:Button id="refreshButtonlLandscape" icon="@Embed('assets/refresh160.png')" click="refreshRSS(event)" />
</s:actionContent.landscape>
<s:actionContent.portrait>
<s:Button id="refreshButton" icon="@Embed('assets/refresh160.png')" click="refreshRSS(event)" />
<s:Button id="navigatorButton" label="Search" click="splitViewNavigator.showFirstViewNavigatorInPopUp(navigatorButton)" />
</s:actionContent.portrait>
</s:ViewNavigator>
</s:SplitViewNavigator>
</s:View>
回答1:
Okay I see what the problem is I think. You're creating a new instance of the redditFeed object instead of using the one instantiated in MXML. In your RedditReaderHomeView.mxml give the declaration of redditFeed an id, then in the function above use it like:
private var redditFeedId:RedditFeed; //Passed in from RedditReaderHome, bound to the id of the actual one in there
public function list_clickHandler(event:IndexChangeEvent):void {
var RSSItem:Object = redditList.dataProvider.getItemAt(event.newIndex);
var thisItem:Item = RSSItem as Item;
rlink = thisItem.link;
var moddedLink:String = rlink.slice(1, int.MAX_VALUE)
redditFeedId.myList_creationCompleteHandler(moddedLink);
}
Paste in RedditReaderHome if you end up needing any help on that.
Thanks for following up [ADDED]
public function refreshRSS(event : Event) : void
{
trace(redditFeedNav.getElementAt(0));
redditFeedNav.getElementAt(0).refreshList();
}
来源:https://stackoverflow.com/questions/9222639/how-do-i-use-a-splitviewnavigator-component-to-show-master-detail-navigation-in