---
title: "FLEX中如何访问服务器的本地绝对路径图片"
author: "wwwtete"
date: "2010-11-01T15:01:58Z"
tags: []
categories: ["Web前端"]
slug: "flex"
draft: false
lastmod: "2010-11-01T16:49:38Z"
id: 799603
url: "https://wwwflex.iteye.com/blog/799603"
---

```
 
```

  在做项目的时候，画面初始化将部分服务器上的图片显示在画面的IMAGE控件上。可如果动态更改IMAGE控件的source属性图片就会不显示图片了，不知道怎么指定服务器的绝对路径。  
测试代码如下：  
public function init():void{  
var \_imgComponent:Image;  
for (var i:int;i&lt;10;i++){  
\_imgComponent = new Image();  
\_imgComponent.width = 135;  
\_imgComponent.height = 100;  
\_imgComponent.source = "d:/img001.jpg";  
this.hbPicBox.addChild(\_imgComponent);  
}  
}

hbPicBox是HBOX容器，循环将10个图片放入到容器中，现在我TOMCAT服务器的D盘根目录下有个img001.jpg文件，  
怎么能读取出来？  
试过网上的-use-network=false和SYSTEM32\\Macromed\\Flash\\FlashPlayerTrust目录下建文件的方式，但都没成功，终于在CSDN论坛上找到了解决方案，希望能对大家有所帮助吧：

```
			import mx.core.Application;
			var tempStr:String = Application.application.url;
			var serverName:String = URLUtil.getServerName(tempStr);
			var serverPort:String = URLUtil.getPort(tempStr).toString();
			var serverProtocol:String = URLUtil.getProtocol(tempStr);

			var httpURL:String = serverProtocol + "://" + serverName + ":" +serverPort+"/服务器上项目名称/";
//然后将IMAGE控件的source属性更改一下即可
_imgComponent.source = httpURL+"img001.jpg";
```