A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Why does it get error if i write i:int = 0; i > _drives:lengh ... Windows "C:\"

  1. #1
    Junior Member
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    15

    Why does it get error if i write i:int = 0; i > _drives:lengh ... Windows "C:\"

    Hello guys and ladies

    How do i fix for Drive C: If Adobe AIr detects to default drive C:\ or Installed Windows OS D:\ or E:\ ...

    I have created code for FileUtils.as
    Code:
    package net.sourceskyboxer.flexos.command.utils
    {
    	import flash.filesystem.File;
    
    	public class FileUtils
    	{
    		private static var _drive:File
    		private static var _drives:Array;
    		
    		private static const DRIVE_C:String = "C:";
    		private static const DRIVE_D:String = "D:";
    		private static const DRIVE_E:String = "E:";
    		private static const DRIVE_F:String = "F:";
    		private static const DRIVE_G:String = "G:";
    		
    		
    		public static function get WindowsSystemDrive():File
    		{
    			_drives = File.getRootDirectories();
    			var i:int = 0; i < _drives.length;
    			if(_drives[i] == _drive.getDirectoryListing())
    			{
    				if(_drives[i].name == DRIVE_C)
    				{
    					_drive = _drives[i].esolvePath(DRIVE_C);
    				}
    			}
    			return _drive;
    		}
    	}
    }
    And i try from code - but it does not work. Why do i not get C:\ If i have installed Windows in Drive C:\.

    drive_C_Windows_installed.PNG

    Adobe Air Application got error:
    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at net.sourceskyboxer.flexos.command.utils::FileUtils$/get WindowsSystemDrive()[C:\Users\Joe\Adobe Flash Builder 4.6\FlexOS Command\src\net\sourceskyboxer\flexos\command\utils\FileUtils.as:22]
    	at fxCommand/onCreationCompleteHandler()[C:\Users\Joe\Adobe Flash Builder 4.6\FlexOS Command\src\fxCommand.mxml:27]
    	at fxCommand/___fxCommand_WindowedApplication1_creationComplete()[C:\Users\Joe\Adobe Flash Builder 4.6\FlexOS Command\src\fxCommand.mxml:5]
    	at flash.events::EventDispatcher/dispatchEventFunction()
    	at flash.events::EventDispatcher/dispatchEvent()
    	at mx.core::UIComponent/dispatchEvent()[/Users/erik/Documents/ApacheFlex/git/flex-sdk_RC2/flex-sdk/frameworks/projects/framework/src/mx/core/UIComponent.as:13688]
    	at mx.core::UIComponent/set initialized()[/Users/erik/Documents/ApacheFlex/git/flex-sdk_RC2/flex-sdk/frameworks/projects/framework/src/mx/core/UIComponent.as:1839]
    	at mx.managers::LayoutManager/doPhasedInstantiation()[/Users/erik/Documents/ApacheFlex/git/flex-sdk_RC2/flex-sdk/frameworks/projects/framework/src/mx/managers/LayoutManager.as:850]
    	at mx.managers::LayoutManager/doPhasedInstantiationCallback()[/Users/erik/Documents/ApacheFlex/git/flex-sdk_RC2/flex-sdk/frameworks/projects/framework/src/mx/managers/LayoutManager.as:1188]
    How do i fix it? Please help me! Thanks I am bit mad because code was before good working than it is not working today. I don't understand. Drive C:\ if i have installed Windows in Partition "C:\".

    Thanks

  2. #2
    Junior Member
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    15
    Hello sirs & ladies,

    I have biggest problem with Adobe Air and Windows Binaries.

    I have created simple "HomeDrive():File" for C:\ or D:\ If you have installed Windows OS on current drive-letter
    Code:
    		public static function get HomeDrive():File
    		{
    			var _drives:Array = File.getRootDirectories()
    			for ( var i:int = 0;  i < _drives.length; i++)
    			{
    				if(_drives[0].exists)
    				{
    					_homeDrive = _drives[0]
    				}
    			}
    			return _homeDrive;
    		}
    And i have created same directories for Windows and System32 folders..
    Code:
    		public static function get WindowsDirectory():File
    		{
    			if (osName.indexOf("win") > -1)
    			{
    				_winDir = FileUtils.HomeDrive.resolvePath(WINDOWS_PATH);
    			}
    			return _winDir;
    		}
    
    		public static function get System32Directory():File
    		{
    			if (osName.indexOf("win") > -1)
    			{
    				_sys32 = FileUtils.WindowsDirectory.resolvePath(SYSTEM32_PATH);
    			}
    			return _sys32;
    		}
    I have built simple RegistryModify by ya110 but i don't need to use py2exe-binary.
    I use simple native path to reg.exe from C:\Windows\System32\reg.exe

    But my code is not finish.
    Code:
    package net.sourceskyboxer.utils
    {
    	import flash.desktop.NativeProcess;
    	import flash.desktop.NativeProcessStartupInfo;
    	import flash.events.Event;
    	import flash.events.EventDispatcher;
    	import flash.events.NativeProcessExitEvent;
    	import flash.events.ProgressEvent;
    	
    	public class RegModifer extends EventDispatcher
    	{
    		private var _np:NativeProcess;
    		private var _npi:NativeProcessStartupInfo;
    		private var _args:Vector.<String>;
    		private var _exePath:String;
    		public var _output:String;
    		
    		public function RegModifer()
    		{
    			_exePath = FileUtils.System32Directory.resolvePath("reg.exe").nativePath;
    		}
    		
    		public function addKey(_rootKey:String, _path:String, _key:String, _value:String):void
    		{
    			_args = new Vector.<String>;
    			_args.push(' add \"'+_rootKey+_path+'\" /v \"'+_key+'\" /t REG_SZ /d \"'+_value+'\"');
    			regProgress();
    		}
    
    		private function regProgress():void
    		{
    			_npi = new NativeProcessStartupInfo();
    			_npi.executable = FileUtils.System32Directory.resolvePath("reg.exe");
    			_npi.arguments = _args;
    			
    			_np = new NativeProcess();
    			_np.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
    			_np.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
    			_np.addEventListener(NativeProcessExitEvent.EXIT, onExit);
    			_np.start(_npi)
    		}
    		
    		public function get output():String
    		{
    			return _output;
    		}
    		
    		private function onOutputData(e:ProgressEvent):void {
    			_output = String(_np.standardOutput.readUTFBytes(_np.standardOutput.bytesAvailable));
    			dispatchEvent(new Event("OutputData"));
    		}
    		
    		private function onErrorData(e:ProgressEvent):void {
    			_output = String(_np.standardError.readUTFBytes(_np.standardError.bytesAvailable));
    			dispatchEvent(new Event("ErrorData"));
    		}
    		
    		private function onExit(e:NativeProcessExitEvent):void {
    			_np.removeEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
    			_np.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
    			_np.removeEventListener(NativeProcessExitEvent.EXIT, onExit);
    			_npi = null;
    			_np = null;
    			_args = null;
    			dispatchEvent(new Event(Event.COMPLETE));
    		}
    	}
    }
    Than i have created Flex Project. I am tried but i have correct application name of exe.

    Why does it happen if it shows "Error: Wrong argements/options" What does it mean? I have written current reg add "HKCU\<-Path-> /v <-Key-> /t REG_SZ /d <- Value ->

    I don't understand why does Adobe Air go wrong?

    How do i fix? Maybe " or ' ??
    My code:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
    						xmlns:mx="library://ns.adobe.com/flex/mx"
    						layout="absolute" showStatusBar="false" usePreloader="false"
    						creationComplete="onCreationCompleteHandler(event)">
    	<fx:Script>
    		<![CDATA[
    			import flash.net.dns.AAAARecord;
    			import flash.sampler.NewObjectSample;
    			
    			import mx.core.Window;
    			import mx.events.FlexEvent;
    			
    			import net.sourceskyboxer.utils.CommandModifer;
    			import net.sourceskyboxer.utils.FileUtils;
    			import net.sourceskyboxer.utils.RegModifer;
    			import net.sourceskyboxer.utils.Rundll32Modifer;
    			
    			private var installPathDir:File;
    			
    			private var cm:CommandModifer;
    			private var rm:RegModifer;
    			private var appPath:String = File.applicationDirectory.nativePath+File.separator+"fxCommand.exe";
    			
    			protected function onCreationCompleteHandler(event:FlexEvent):void
    			{
    				
    				testdrive.text = FileUtils.HomeDrive.nativePath;
    				
    				/**
    				 * 	Call from kernel32.dll, peep();
    				 */
    				var rundll:Rundll32Modifer = new Rundll32Modifer();
    				
    			}
    			
    			private function onError(e:Event):void {
    				cmdMessage.text = cm._output;
    			}
    			
    			private function onReadTerminal(e:Event):void {
    				cm.removeEventListener("OutputData", onReadTerminal);
    				cmdMessage.text = cm._output;
    			}
    			
    			protected function chooseHandler(event:MouseEvent):void
    			{
    				installPathDir = new File();
    				installPathDir.browseForDirectory("Choose to installing application");
    				installPathDir.addEventListener(Event.SELECT, onChooseDir);
    			}
    			
    			private function onChooseDir(evt:Event):void
    			{
    				testdrive.text = installPathDir.nativePath;
    			}
    			
    			protected function RunAsHandler(event:MouseEvent):void
    			{
    				rm = new RegModifer();
    				rm.addKey("HKCU","\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers",appPath,"RUNASADMIN");
    				rm.addEventListener("OutputData", onWriteComplete);
    				rm.addEventListener("ErrorData", onRegError);
    			}
    			
    			private function onWriteComplete(e:Event):void {
    				rm.removeEventListener("OutputData", onWriteComplete);
    				cmdMessage.text = rm._output;
    			}
    			
    			private function onRegError(e:Event):void {
    				cmdMessage.text = rm._output;
    			}
    		
    			
    			
    		]]>
    	</fx:Script>
    	<fx:Declarations>
    		<!-- Platzieren Sie nichtvisuelle Elemente (z.*B. Dienste, Wertobjekte) hier -->
    	</fx:Declarations>
    	<mx:TextArea left="10" right="10" top="10" bottom="40" id="cmdMessage"/>
    	<mx:TextInput id="testdrive" left="10" right="172" bottom="10"/>
    	<mx:Button right="10" bottom="10" label="Runas" click="RunAsHandler(event)"/>
    	<mx:Button right="85" bottom="10" label="Choose..." click="chooseHandler(event)"/>
    </mx:WindowedApplication>
    P.S: Please delete / ignone same important library because i don't give it.

    And i compile into Adobe Air Captive Runtime than it shows error:


    I try with terminal of WIndows: cmd:

    It is successful but Adobe Air is stupid because it can not call current? How do i fix?

    You know like Languages.. Sorry German Language i am using Windows OS

    Can you help me ?
    Attached Images Attached Images
    Last edited by SourceSKyBoxer; 05-18-2015 at 05:08 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center