我创建了一个类(一个audio播放的),现在使用它,代码基本组成如下:
class webform1
Public WavTarget As String private objplayer as new clsplayer(……) '创建 Private Sub Page_Load…………
这样系统会报错,未将对象引用到实例什么什么的我换了一种方式,
class webform1
Public WavTarget As String private objplayer clsplayer '申明 Private Sub Page_Load…………
player=new clsplayer(……)
end sub
象这样子后,在别的地方这个player引用不了了!比如我在一个按钮里面open一段声音,在另一个按钮里面却无法用close方法关闭了
请问象这样子的公共对象的应该如何使用?
class webform1
Public WavTarget As String private objplayer as new clsplayer(……) '创建 Private Sub Page_Load…………
这样系统会报错,未将对象引用到实例什么什么的我换了一种方式,
class webform1
Public WavTarget As String private objplayer clsplayer '申明 Private Sub Page_Load…………
player=new clsplayer(……)
end sub
象这样子后,在别的地方这个player引用不了了!比如我在一个按钮里面open一段声音,在另一个按钮里面却无法用close方法关闭了
请问象这样子的公共对象的应该如何使用?
{
get
{
if( Session["objplayer"]==null )
return null;
else
return (clsplayer)Session["objplayer"];
}
set{ Session["objplayer"] = value; }
}
Private Sub Page_Load…………
objplayer=new clsplayer(……)
end sub
这样子就可以在另一按钮中调用close了: this.objplayer.close()....
但是你的代码好像有问题。
1、“private objplayer clsplayer”声明不对,没有As
2、 声明变量是objplayer,而方法内使用player。
看看是不是这个引起的问题。
刚开始做asp.net什么都不懂!大家在这种方面还有什么心得,比如说什么公共变量之类的,说一说啊,小弟也好跟着进步进步,现在去试!可以马上加分!!
objPlayer = New AudioPlayer.clsAudioPlayer
objWave = New AudioFile(Session("SN")) Session("objPlayer") = objPlayer
Session("objWave") = objWave
………………sub XXX
CType(Session("objPlayer"), AudioPlayer.clsAudioPlayer).mmOpen(CType(Session("objWave"), AudioFile).GetMusic())
CType(Session("objPlayer"), AudioPlayer.clsAudioPlayer).mmPlay()
…………
end sub
这么写后,在 AudioFile 类中所有的server.mappath都不能映射路径了!!这个类里面我是
inherits system.web.ui.page 这么做行不行,哪位大哥能指点指点
高手们帮忙看看! 未能映射路径“/TRS-WEB/tmp/tmp20050615164131.wav”[HttpException (0x80004005): 未能映射路径“/TRS-WEB/tmp/tmp20050615164131.wav”。]
System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.MapPathSlowUsingIISCore(String path) +197
System.Web.Hosting.ISAPIWorkerRequest.MapPath(String path) +420
System.Web.HttpRequest.MapPath(String virtualPath, String baseVirtualDir, Boolean allowCrossAppMapping)
System.Web.HttpRequest.MapPath(String virtualPath)
System.Web.HttpServerUtility.MapPath(String path)
TRS_WEB.AudioFile.GetMusic() in C:\Inetpub\wwwroot\TRS-WEB\AudioFile.vb:84
TRS_WEB.cls_page_Play.Button2_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\TRS-WEB\Player.aspx.vb:217
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
inherits system.web.ui.page 这么做行不行,哪位大哥能指点指点
========================
在AudioFile中用
System.Web.HttpContext.Current.Server.MapPath(..)就可以了
hackate(兰花开香入梦境,独思佳人亦飘然!!)
luckljtchinaren(Lucky)每人50了哇!!!
接分接分!!最好能留个联系方式下来哎!!!太感谢了!!~
hackate(兰花开香入梦境,独思佳人亦飘然!!) 大哥能不能给我讲讲这个原理哇?为什么用
System.Web.HttpContext.Current.Server.MapPath(..)就可以,直接用mappath就不可以呢??