0

我有一个 remoteobject 类来处理与我的远程数据服务的所有交互。每次进行调用时,数据服务都会检查用户是否具有有效会话。如果他们不这样做,它将不会运行请求的方法并返回失败。我可以在故障处理程序中捕获此失败。如果发生这种情况,我想做的是将登录屏幕推送给用户。

我试过以下

            var navigator:ViewNavigator;
            navigator.activeView.navigator.pushView(views.LoginScreen);

但这不起作用,并且由于无法访问空对象引用的属性或方法而失败。这是有道理的。所以我的问题是如何获得对当前正在运行的视图导航器对象的引用并推送视图?

谢谢

这里要求的是完整的远程对象类

包远程处理 { 导入事件.RemoteExceptionEvent;

import flash.events.*;

import mx.managers.CursorManager;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.events.FaultEvent;
import mx.rpc.remoting.RemoteObject;

import spark.components.ViewNavigator;

import views.FirstTime.ValidateUser;

/**
 * Super class for all remote services that contains some generic methods.
 */
public class RemoteService extends EventDispatcher

{
    private static var REMOTE_EXCEPTION:String = "Remote exception";
    private static var NO_MESSAGE:String = "10001";

    protected var remoteObject:RemoteObject;

    private var amfChannelSet:ChannelSet;

    /**
     * Constructor accepting an id and destination for the actual RemoteObject to create. An event listener
     * is added for exceptions.
     * @param id String representing the id of the new RemoteObject to create
     * @param destination String representing the destination of the RemoteObject to create
     * @param amfChannelId String representing the Channel of the RemoteObject to create
     * @param amfChannelEndpoint String representing the Endpoint URI of the RemoteObject to create
     */
    public function RemoteService( serviceId:String
                                   , serviceDestination:String
                                     , amfChannelId:String
                                       , amfChannelEndpoint:String
    ) 
    {
        // Create a runtime Channelset for given Channel ID and Endpoinr URI
        var amfChannel:AMFChannel = new AMFChannel(amfChannelId, amfChannelEndpoint);
        amfChannelSet = new ChannelSet();
        amfChannelSet.addChannel(amfChannel);

        // Create the remoteObject instance
        this.remoteObject = new RemoteObject(serviceId);
        this.remoteObject.channelSet = amfChannelSet;
        this.remoteObject.destination = serviceDestination;
        this.remoteObject.addEventListener(FaultEvent.FAULT,onRemoteException);
        this.remoteObject.setCredentials('test','test');

    }

    /**
     * generic fault event handler for all remote object actions. based on the received message/code an action
     * is taken, mostly throwing a new event.
     * @param event FaultEvent received for handling
     */
    public function onRemoteException(event:FaultEvent):void {
        trace('code : ' + event.fault.faultCode +
            ', message : ' + event.fault.faultString +
            ',detail : ' + event.fault.faultDetail);

            trace('fodun: ' + event.fault.faultDetail.indexOf("Authentication"));

        if (event.fault.faultDetail.indexOf("Authentication") > 0)
        {

            var navigator:ViewNavigator;

             navigator.activeView.navigator.pushView(views.LoginScreen);



        }
        else  if (event.fault.faultString == REMOTE_EXCEPTION) {
            EventDispatcher(
                new RemoteExceptionEvent(RemoteExceptionEvent.REMOTE_EXCEPTION,
                    "unknown problem occurred during a remote call : " + event.fault.message));
        } else if (event.fault.faultCode == NO_MESSAGE) { 
            EventDispatcher(
                new RemoteExceptionEvent(RemoteExceptionEvent.REMOTE_EXCEPTION,
                    event.fault.faultString));
        } else {

            EventDispatcher((
                new RemoteExceptionEvent(RemoteExceptionEvent.REMOTE_EXCEPTION,
                    "unknown runtime problem occurred during a remote call : " + event.fault.message)));
        }
    }
}
}
4

1 回答 1

0

从 RemoteService 类中访问您的视图或任何可视化组件并不是处理 MVC 应用程序的好方法。您要做的是在您的 RemoteService 类中分派一个事件,该事件基本上说“身份验证失败”。然后,在您看来,您将侦听此事件并将其解释为显示登录屏幕的需要。看 ?

于 2011-11-16T11:02:26.700 回答