Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-20-2008, 02:14 AM
Junior Member
 
Join Date: Jun 2008
Posts: 4
Default As3, Dialogs, How to use it?Please show me the sample?Sorry for my pool english!

Use as3, I can open a browse to get a file(like *.jpg),and get it's name,the swf can do that well,but it can't get the file's path(Maybe I'm wrong) . If the file dosn't in the same dir with the swf,the swf can't find the pic's path,when I want show the pic,it dosn't work.

So I want to use SWFKit to get the file's full path(like "c:\images\pic.jpg" or "d:\myfiles\images\pic.jpg" ), I learn the sample about to do this use as2,SWFKit do it well,but when I use as3,I can't do it well,infact I have no idea how to do it now.

So,SWFKit or anyone can help me?

Thank you very much!And sorry for my pool english

here is the as3 code:
Code:
package {
	import flash.display.Sprite;
	import flash.events.*;
	import flash.net.*;
	import flash.net.FileReference;


	public class URLRequestExample extends Sprite {
		private var file:FileReference;
		public function URLRequestExample() {

			file= new FileReference();
			file.addEventListener(Event.SELECT, selectHandler);
			file.browse(getTypes());

		}
		private function getTypes():Array {
			var allTypes:Array = new Array(getImageTypeFilter());
			return allTypes;
		}
		private function getImageTypeFilter():FileFilter {
			return new FileFilter("xml(*.xml)","*.xml");
		}
		private function selectHandler(event:Event):void {
			var file:FileReference = FileReference(event.target);

			var loader:URLLoader = new URLLoader();
			configureListeners(loader);
			var request:URLRequest = new URLRequest(file.name);
			try {
				loader.load(request);

			} catch (error:Error) {
				trace("Unable to load requested document.");
			}
		}

		private function configureListeners(dispatcher:IEventDispatcher):void {
			dispatcher.addEventListener(Event.COMPLETE, completeHandler);
			dispatcher.addEventListener(Event.OPEN, openHandler);
			dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
			dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
			dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
			dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
		}

		private function completeHandler(event:Event):void {
			var loader:URLLoader = URLLoader(event.target);
			trace("completeHandler:data= " + loader.data+"\n");
		}

		private function openHandler(event:Event):void {
			trace("openHandler:event= " + event+"\n");
		}

		private function progressHandler(event:ProgressEvent):void {
			trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal+"\n");
		}

		private function securityErrorHandler(event:SecurityErrorEvent):void {
			trace("securityErrorHandler: " + event+"\n");
		}

		private function httpStatusHandler(event:HTTPStatusEvent):void {
			trace("httpStatusHandler: " + event+"\n");
		}

		private function ioErrorHandler(event:IOErrorEvent):void {
			trace("ioErrorHandler: " + event+"\n");
		}
	}
}
Reply With Quote
  #2 (permalink)  
Old 06-20-2008, 03:24 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: As3, Dialogs, How to use it?Please show me the sample?Sorry for my pool english!

Code:
import SWFKit.*;

var dlg = new Dialogs;
var file = dlg.fileOpen("JPG files(*.jpg)|*.jpg|");
Reply With Quote
  #3 (permalink)  
Old 06-21-2008, 02:25 AM
Junior Member
 
Join Date: Jun 2008
Posts: 4
Default Re: As3, Dialogs, How to use it?Please show me the sample?Sorry for my pool english!

Thank SWFKIT very much!

Here is the sample file,I wish it well be useful to somebody!

http://www.dao28.com/temp/load_pic.rar

Here is the as:
Code:
package {
	import flash.display.*;
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.ui.*;
	import flash.events.*;
	import flash.system.LoaderContext;
	import flash.system.fscommand;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFieldAutoSize;
	import flash.events.TextEvent;
	import fl.controls.Button;
	import SWFKit.*;

	public class pic extends Sprite {

		private var info:TextField = new TextField();
		private var txt:TextField = new TextField();
		private var btn:Button;
		private var btn2:Button;
		private var loader:Loader;

		public function pic() {
			TextEvent_info_input();
		}
		public function TextEvent_info_input() {
			info.x = 40;
			info.y = 466;
			info.height = 20;
			info.width = 250;
			info.background = true;
			info.border = true;
			info.type = TextFieldType.INPUT;
			info.text = "Please input the pic's path: ";
			this.addChild(info);
			txt.x = 40;
			txt.y = 440;
			txt.height = 20;
			txt.width = 420;
			txt.htmlText="<font color='#333333'><a href='http://www.123flashchat.com'>copyright "+"\u00A9"+" www.123flashchat.com</a></font>";
			addChild(txt);

			btn = new Button();
			btn.label = "loading pic...";
			btn.move(info.width+60,466);
			btn.width = 70;
			btn.addEventListener(MouseEvent.CLICK, buttonClick);
			addChild(btn);
			btn2 = new Button();
			btn2.label = "browse";
			btn2.move(info.width+140,466);
			btn2.width = 70;
			btn2.addEventListener(MouseEvent.CLICK, buttonClick2);
			addChild(btn2);

			var myContextMenu:ContextMenu = new ContextMenu();
			myContextMenu.hideBuiltInItems();
			var item:ContextMenuItem = new ContextMenuItem("exit");
			myContextMenu.customItems.push(item);
			this.contextMenu = myContextMenu;
			item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT ,mouseRelease);
		}
		private function mouseRelease(event:ContextMenuEvent) {
			fscommand("quit");
		}
		private function buttonClick(e:MouseEvent) {
			var button:Button = e.target as Button;
			var lc:LoaderContext = new LoaderContext(true);
			var loader:Loader = new Loader();
			loader.load(new URLRequest(info.text),lc);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, pic_completeHandler);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);

		}
		private function buttonClick2(e:MouseEvent) {

			var dlg = new Dialogs;
			var file = dlg.fileOpen("JPG files(*.jpg;*.gif;*.png)|*.jpg;*.gif;*.png|");
			var lc:LoaderContext = new LoaderContext(true);
			var loader:Loader = new Loader();
			loader.load(new URLRequest(file),lc);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, pic_completeHandler);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
		}

		private function loadProgress(event:ProgressEvent):void {
			var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
			percentLoaded = Math.round(percentLoaded * 100);
			txt.htmlText="<font color='#681041'><a href='http://www.123flashchat.com/'>copyright "+"\u00A9"+"www.123flashchat.com</a></font>"+" per:"+percentLoaded+"%";
		}
		private function pic_completeHandler(event:Event) {
			var loader:Loader = Loader(event.target.loader);
			addChild(loader);
			loader.x=50;
			loader.y=10;
			loader.scaleX=0.7;
			loader.scaleY=0.7;
		}
	}
}
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:15 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.