近年来想做1个flash的菜系与asp.net进行交互. 参考了不少网上的资料,最后有以下心得,写出来记一下。

壹 、动态加载菜单
    菜单的始末如下(menu.xml):
<?xml version=”1.0″ encoding=”utf-8″?>
<navigation>
 <menu id=”2″ menutext=”编辑角色” menuurl=”艾德itRole.aspx”>
 </menu>
<menu id=”4″ menutext=”应用程序分配”
menuurl=”PrincipalInApp.aspx”>
 </menu>
 <menu id=”5″ menutext=”权限管理”
menuurl=”PrincipalInResource.aspx”>
</menu>
</navigation>

如若动态加载呢?

  1)把以menu.xml文件放到网站的根目录之下,然后在flash的as中写如下的as脚本.
  
mymenu = new XML();
mymenu.load(“menu.xml”);
mymenu.ignoreWhite = true;
mymenu.onLoad = findThefild;
var passItOn = “”;
menu_text = “”;
var menu_array = new Array();
var submenu_array = new Array();
var menuurl_array = new Array();
var submenuurl_array = new Array();
var tempArray:Array = new Array();

那般就足以把菜单加载到flash中,至于怎么着呈现,就协调开始展览处理了.

 ② 、  给菜单中添加动态参数.
    
大家很多年华利用的url都是如艾德itRole.aspx?rolename=role1之类,此时应有怎么着把”?rolename=role1″动态的传给flash呢.
     作者试验了很多形式,最后的结果如下. 
1) 
说一下有了flash之后的asp.net页面包车型地铁生成顺序.例如小编的页面是editrole.aspx在此页面中有二个flash菜单.
     editrole.aspx–>flash–>与flash通讯的页面.
2)  怎么着把动态参数字传送给flash呢,作者动用的是xml让asp.net与flash进行通讯.
3) 
那么动态参数怎么着赢得呢?那即将借用第玖个页面,也正是特意用来与flash实行互动的页面.而不能够运用所点击的菜单的页面.
4) 
如上在率先个打开的页面如艾德itRole.aspx?rolename=role第11中学把”?rolename=role1″保存到cookie或缓存或seession中,
     
然后则越发与flash进行通讯的页面把”?rolename=role1″编写成xml,然后reponse.wirte(参数xml字符串),传给flash.

    代码:

      1.editrole.aspx页面中的代码.
       protected void Page_Load(object sender, EventArgs e)
        {
            this.txtUserName.Text = this.UserName;
            //this.Description.Text = ReponseXML();
            if (!IsPostBack)
            {
                ShowUserInfo();
               this.WirteCookie();
            }

           
        }
       
         public void WirteCookie()
        {
       
            //加密程序提供程序的称呼
            string symmProvider = “DESCryptoServiceProvider”;
            //须要加密的xml字符串
            string stringToEncrypt = this.ReponseXML();
            //加密后的字符串
            string encryptedContentsBase64 =
Cryptographer.EncryptSymmetric(symmProvider, stringToEncrypt);

      //写cookies
            Response.Cookies[“UserSettings”][“uid”] =
encryptedContentsBase64;

            Response.Cookies[“UserSettings”][“ur”]
=this.UserRole;
                Response.Cookies[“UserSettings”].Expires =
DateTime.Now.AddHours(1);

  
           
        }

           protected string ReponseXML()
        {
        string param=””;
             int index=Request.Url.ToString().IndexOf(“?”);
          if (index>0)
          {
               param=Request.Url.ToString().Substring(index);
         
          }
        
          return  “<LOGIN><USRENAME name=\”user\”
right=\”1\” urlParam=\”” + param +
“\”>”+param+”</USERNAME></LOGIN>”;
           
        }
//与flash实行交互的页面.
    [WebService(Namespace = “http://tempuri.org/")\]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class XmlRepley : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = “text/xml”;
         //   context.Response.Write(“Hello World”);

            string symmProvider = “DESCryptoServiceProvider”;
            string stringToEncrypt = this.GetUID(context);
            string decryptedContentsBase64 =
Cryptographer.DecryptSymmetric(symmProvider, stringToEncrypt);

           context.Response.Write(decryptedContentsBase64);
        }

        public string GetUID(HttpContext context)
        {
            string uid = String.Empty;
            if (context.Request.Cookies[“UserSettings”] != null)
            {

                if (context.Request.Cookies[“UserSettings”][“uid”]
!= null)
                { uid
=context.Request.Cookies[“UserSettings”][“uid”]; }

            }
            return uid;

        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

  
  
  
   //flash中as代码
  
  
//———————————————————–
//鼠标点击菜单时
//———————————————————–
function itemEvent(mc:MovieClip,url:String)
{
 
 mc.btn.onRelease = function()
 {

loginXml = new XML(); // 注释1
loginElement = loginXml.createElement(“LOGIN”); // 注释2
// name node
nameElement = loginXml.createElement(“USERNAME”); // 注释3
nameNode = loginXml.createTextNode(“name”); // 注释4
nameNode.nodeValue = _root.username; // 注释5
nameElement.appendChild(nameNode); // 注释6
// pwd node
pwdElement = loginXml.createElement(“PWD”); // 注释7
pwdNode = loginXml.createTextNode(“pwd”);
pwdNode.nodeValue = _root.pwd;
pwdElement.appendChild(pwdNode);
loginElement.appendChild(nameElement); // 注释8
loginElement.appendChild(pwdElement); // 注释9

loginXml.appendChild(loginElement); // 注释10

xmlRepley = new XML(); // 注释11

xmlRepley.onLoad = onLoginReply; // 注释12
function onLoginReply (success) {
if (success) { // 注释13

if (xmlRepley.firstChild.firstChild.attributes.right == “1”) { //
注释14
getURL(url+xmlRepley.firstChild.firstChild.attributes.urlParam,
“_self”);

}
else
{
 getURL(url+”?q=错误”, “_self”);
}
}
}
loginXml.sendAndLoad(“XmlRepley.ashx”, xmlRepley); // 注释15

 }
}

 

 ③ 、加载动态菜单项   

 
以上的菜系都是flash去读xml菜单文件,那么一旦大家有多少个不一致系列的食谱,则要做三个不等的flash,
 
而那多少个不财的flash中,固然菜单样式一样,只可是是菜单的内容分歧,那么实际上是去读不相同的xml菜单文件.
  那么有没有主意去落实有先后去给定一个flash菜单的xml数据源呢?
 
   作者试验了重重主意,最终的结果如下.
  
1)说一下有了flash之后的asp.net页面包车型大巴生成顺序.例如小编的页面是editrole.aspx在此页面中有1个flash菜单.
   editrole.aspx–>flash–>与flash通讯的页面.
   2)怎样把xml菜单传给flash呢,作者利用的是xml让asp.net与flash实行通信.
   

      代码
  1)在flash的as中写如下的as脚本,获得xml文件菜单.
     
mymenu = new XML();
mymenu.load(“SendXmlMenu.ashx”);
mymenu.ignoreWhite = true;
mymenu.onLoad = findThefild;
var passItOn = “”;
menu_text = “”;
var menu_array = new Array();
var submenu_array = new Array();
var menuurl_array = new Array();
var submenuurl_array = new Array();
var tempArray:Array = new Array();

2)在主角色页面如showRoleMenu.aspx页面中写如下代码
 protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cookies[“UserSettings”][“ur”] = “r”;
//新页面要开拓的菜单.
            Response.Cookies[“UserSettings”].Expires =
DateTime.Now.AddHours(1);  

        }
       
        在主用户页面如showUserMenu.aspx页面中写如下代码
       
 protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cookies[“UserSettings”][“ur”] = “u”;
//新页面要开拓的菜单.
            Response.Cookies[“UserSettings”].Expires =
DateTime.Now.AddHours(1);  

        }
       
              
   3)在SendXmlMenu.ashx中写以下代码实行xml菜单的传给flash.
  

   [WebService(Namespace = “http://tempuri.org/")\]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class SendXmlMenu : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = “text/xml”;
            context.Response.Write(ReadXmlMenu(context));
           
        }
        public string ReadXmlMenu(HttpContext context)
        {
            string ur = this.GetUserRole(context);
            System.Xml.XmlDocument xmldoc = new
System.Xml.XmlDocument();
            string
path=context.Request.PhysicalPath.Substring(0,context.Request.PhysicalPath.LastIndexOf(“\\”));
            path = path + “\\menu\\”;
            switch(ur.ToLower())
            {
                case “u”://那么些参数通过cookie得到.
                    xmldoc.Load(path + “usermenu.xml”);
                    return xmldoc.OuterXml;
                case “r”:
                    xmldoc.Load(path + “rolemenu.xml”);
                    return xmldoc.OuterXml;
                default:
                    return String.Empty;

            }

        }

        public string GetUserRole(HttpContext context)
        {
            string ur = String.Empty;
            if (context.Request.Cookies[“UserSettings”] != null)
            {

                if (context.Request.Cookies[“UserSettings”][“ur”]
!= null)
                { ur =
context.Request.Cookies[“UserSettings”][“ur”]; }

            }
            return ur;

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

如果有怎么着不足的地点请指正。

相关文章

网站地图xml地图