从动作脚本类推送视图

发布于 2024-12-16 01:21:27 字数 3959 浏览 1 评论 0原文

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

我已经尝试了以下方法

            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)));
        }
    }
}
}

I have a remoteobject class that handles all interactive with my remote data service. each time a call is made the dataservice checks that the user has a valid session. if they don't it won't run the requested method and it returns a fail. I can capture this fail in the fault handler. What I want to do it if it happens is push the login screen to the user.

I have tried the following

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

But this is not working and fails with Cannot access a property or method of a null object reference. which makes sense. so my question is how can I get a reference to the current running view navigator object and push the view?

Thanks

As requested here is the full remote object class

package remoting
{
import events.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)));
        }
    }
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想挽留 2024-12-23 01:21:27

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

Accessing your view or whatever visual components from within a RemoteService class is not a good way to deal with MVC applications. What you want to do is to dispatch an event in your RemoteService class that basically says "authentication has failed". Then, in your view, you'll listen for this event and interpret it as a need to display the login screen. See ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文