鉴's profile鉴赏空间PhotosBlogLists Tools Help

鉴 古

February 11

如何在duplicateMovieClip中传递变量(转载)

 在论坛上看到一个HTML里的FLASH图片切换效果,JS跟FLASH通信,本来觉得没啥特别的,不过仔细看了下发现里面有行代码比较“怪异”,在使用duplicateMovieClip复制MC时,它传递了三个参数:MC新名称、深度、Object类型的一个变量。顿时奇怪了,这个Object有什么作用了?查了下帮助手册,才发现,一直以来自己居然忽视了这么好一个东东,呵呵 太惭愧了下面就来说说这个object到底能干些啥了!
  这是文档里对duplicateMovieClip方法的说明:
  public duplicateMovieClip (name:String, depth:Number, [initObject:Object]) : MovieClip
参数
  name:String - 已重制的影片剪辑的唯一标识符。
  depth:Number - 一个唯一整数,指定要放置新影片剪辑的深度。使用深度 -16384 可将新影片剪辑实例放置在创作环境中创建的所有内容之下。介于 -16383 和 -1(含)之间的值是保留供创作环境使用的,不应与此方法一起使用。其余的有效深度值介于 0 和 1048575(含)之间。
  initObject:Object [可选] - (Flash Player 6 和更高版本支持。)包含用于填充复制影片剪辑的属性的对象。此参数使动态创建的影片剪辑能够接收剪辑参数。如果 initObject 不是对象,则忽略它。initObject 的所有属性都已复制到新实例中。使用 initObject 指定的属性对于构造函数是可用的。
  正是因为intiObject参数可选,我才忽视了这个参数的作用,我想肯定也有朋友跟我一样,这也是我写这篇文章的目的,呵呵 给某些朋友也提个醒。
  从参数说明中可以看出,我们使用initObject参数可以在MC复制时初始化MC的属性,这里的属性可以理解为两方面:
  第一、它是MovieClip类的属性,例如,_x _y _alpha等等我们经常使用的属性
  第二、不是MC固有的属性,而是一个自定义的变量,例如自定义一个link变量。
  在没有使用initObject参数前,我完成MC复制以后还需要一个with来初始化MC的属性,例如:
 
程序代码
for( i=0;i<5;i++){
_mc.duplicateMovieClip("_mc"+i,i);
var _mc = eval("_mc"+i);
with (_mc){
  _x=120*i;
}
}
我们还会遇到一个很常见的问题,例如,我要给每个复制出来的MC初始化一个link,当MC点击时,我要trace出这个link,需求很简单,我们可以尝试写如下代码:
 
程序代码
for (i=0; i<5; i++) {
_mc.duplicateMovieClip("_mc"+i, i);
var _mc = eval("_mc"+i);
//_mc里设置一个_txt文本,用来记录i,假设link等于i
_mc._txt.text = i;    
_mc._x = 120*i;//为每个MC赋予按钮事件,让它能够trace出指定的link
_mc.onRelease = function() {
  trace(i);
};
}

  测试我们发现,复制出来的5个MC的文本显示的确实是0到4,不过当我们点击的时候我们会发现trace出来的都是5,奇怪了,为何我们看到的link是0到4,而我们trace出来的为何是5了?如果对程序内存分配稍微有些了解的话这个就很好理解了,在FLASH里,对于5个MC,我们trace的link变量是占用同一个内存地址。那么如何解决这个问题了?我之前的做法是在复制MC时就给MC一个变量,用来记录link。
 
程序代码
for (i=0; i<5; i++) {
_mc.duplicateMovieClip("_mc"+i, i);
var _mc = eval("_mc"+i);
_mc._txt.text = i;
_mc._x = 120*i;
_mc.link=i;
_mc.onRelease = function() {
  trace(this.link);
};
}
测试,达到我们预期的效果。
现在如果使用initObject参数,那么上面的问题就可以很容易解决了,同时精简了代码量。
 
程序代码
for (i=0; i<5; i++) {
var _obj={link:i,_x:120*i,num:i};
_mc.duplicateMovieClip(”_mc”+i, i,_obj);
var _mc = eval(”_mc”+i);
_mc._txt.text = _mc.num;
_mc.onRelease = function() {
  trace(this.link);
};
}
我们定义了一个名为_obj的Object类型变量,它传递了三个变量,link, _x ,num,其中_x是MC固有属性,那么MC复制出来以后_x坐标自动初始化,不需要我们去设置,对于link , num两个变量相当于我们给每个复制出来的MC都分配了独立的内存空间来存储这两个变量,任何时候我们都可以使用_mc.link来访问这个变量值,而不会出现之前我们遇到的共用内存地址所造成的麻烦了。
  再查阅一下attachMovie方法,它也有一个initObject参数,方式使用和duplicateMovieClip的一样。因此在我们动态复制MC时,如果好好利用这个参数,那么是可以让我们的复制更简洁,更方便。
January 11

如何用flash调用windows user account

想去实现用flash 调用windows user account,但是flash自己根本无法做到。 有人说用php 调用win32 api. 来实现。 但是用php实现window api真是件困难的事情。 因为要涉及在php中调用php_w32api.dll。php本身版本之间就用很多差异。像w32api_register_function这个function 在php4.23以后的版本就不能用了。完全被这个manual 误导了 http://au2.php.net/w32api
 
最后改用ASP 很快就实现了这个功能。
 
username=<%
Dim objNet
Dim username
Set objNet=CreateObject("WScript.NetWork")
response.write(objNet.UserName)
Set objNet = Nothing
%>

如何能完全卸载mysql

有的时候想卸载 mysql但是不能成功。 用一下命令可以实现。
cmd
sc delete mysql

Win32 Functions (转载)

Alphabetical Listing of Win32 Functions

Win32::AbortSystemShutdown(MACHINE)
[EXT] Aborts a system shutdown (started by the InitiateSystemShutdown function) on the specified MACHINE.

Win32::BuildNumber()
[CORE] Returns the ActivePerl build number. This function is only available in the ActivePerl binary distribution.

Win32::CopyFile(FROM, TO, OVERWRITE)
[CORE] The Win32::CopyFile() function copies an existing file to a new file. All file information like creation time and file attributes will be copied to the new file. However it will not copy the security information. If the destination file already exists it will only be overwritten when the OVERWRITE parameter is true. But even this will not overwrite a read-only file; you have to unlink() it first yourself.

Win32::DomainName()
[CORE] Returns the name of the Microsoft Network domain that the owner of the current perl process is logged into.

Win32::ExpandEnvironmentStrings(STRING)
[EXT] Takes STRING and replaces all referenced environment variable names with their defined values. References to environment variables take the form %VariableName%. Case is ignored when looking up the VariableName in the environment. If the variable is not found then the original %VariableName% text is retained. Has the same effect as the following:
        $string =~ s/%([^%]*)%/$ENV{$1} || "%$1%"/eg

Win32::FormatMessage(ERRORCODE)
[CORE] Converts the supplied Win32 error number (e.g. returned by Win32::GetLastError()) to a descriptive string. Analogous to the perror() standard-C library function. Note that $^E used in a string context has much the same effect.
        C:\> perl -e "$^E = 26; print $^E;"
        The specified disk or diskette cannot be accessed

Win32::FsType()
[CORE] Returns the name of the filesystem of the currently active drive (like 'FAT' or 'NTFS'). In list context it returns three values: (FSTYPE, FLAGS, MAXCOMPLEN). FSTYPE is the filesystem type as before. FLAGS is a combination of values of the following table:
        0x00000001  supports case-sensitive filenames
        0x00000002  preserves the case of filenames
        0x00000004  supports Unicode in filenames
        0x00000008  preserves and enforces ACLs
        0x00000010  supports file-based compression
        0x00000020  supports disk quotas
        0x00000040  supports sparse files
        0x00000080  supports reparse points
        0x00000100  supports remote storage
        0x00008000  is a compressed volume (e.g. DoubleSpace)
        0x00010000  supports object identifiers
        0x00020000  supports the Encrypted File System (EFS)

MAXCOMPLEN is the maximum length of a filename component (the part between two backslashes) on this file system.

Win32::FreeLibrary(HANDLE)
[EXT] Unloads a previously loaded dynamic-link library. The HANDLE is no longer valid after this call. See LoadLibrary for information on dynamically loading a library.

Win32::GetArchName()
[EXT] Use of this function is deprecated. It is equivalent with $ENV{PROCESSOR_ARCHITECTURE}. This might not work on Win9X.

Win32::GetChipName()
[EXT] Returns the processor type: 386, 486 or 586 for Intel processors, 21064 for the Alpha chip.

Win32::GetCwd()
[CORE] Returns the current active drive and directory. This function does not return a UNC path, since the functionality required for such a feature is not available under Windows 95.

Win32::GetFullPathName(FILENAME)
[CORE] GetFullPathName combines the FILENAME with the current drive and directory name and returns a fully qualified (aka, absolute) path name. In list context it returns two elements: (PATH, FILE) where PATH is the complete pathname component (including trailing backslash) and FILE is just the filename part. Note that no attempt is made to convert 8.3 components in the supplied FILENAME to longnames or vice-versa. Compare with Win32::GetShortPathName and Win32::GetLongPathName.

This function has been added for Perl 5.6.

Win32::GetLastError()
[CORE] Returns the last error value generated by a call to a Win32 API function. Note that $^E used in a numeric context amounts to the same value.

Win32::GetLongPathName(PATHNAME)
[CORE] Returns a representaion of PATHNAME composed of longname components (if any). The result may not necessarily be longer than PATHNAME. No attempt is made to convert PATHNAME to the absolute path. Compare with Win32::GetShortPathName and Win32::GetFullPathName.

This function has been added for Perl 5.6.

Win32::GetNextAvailDrive()
[CORE] Returns a string in the form of ``<d>:'' where <d> is the first available drive letter.

Win32::GetOSVersion()
[CORE] Returns the array (STRING, MAJOR, MINOR, BUILD, ID), where the elements are, respectively: An arbitrary descriptive string, the major version number of the operating system, the minor version number, the build number, and a digit indicating the actual operating system. For ID, the values are 0 for Win32s, 1 for Windows 9X and 2 for Windows NT. In scalar context it returns just the ID.

Win32::GetShortPathName(PATHNAME)
[CORE] Returns a representation of PATHNAME composed only of short (8.3) path components. The result may not necessarily be shorter than PATHNAME. Compare with Win32::GetFullPathName and Win32::GetLongPathName.

Win32::GetProcAddress(INSTANCE, PROCNAME)
[EXT] Returns the address of a function inside a loaded library. The information about what you can do with this address has been lost in the mist of time. Use the Win32::API module instead of this deprecated function.

Win32::GetTickCount()
[CORE] Returns the number of milliseconds elapsed since the last system boot. Resolution is limited to system timer ticks (about 10ms on WinNT and 55ms on Win9X).

Win32::InitiateSystemShutdown(MACHINE, MESSAGE, TIMEOUT, FORCECLOSE, REBOOT)
[EXT] Shutsdown the specified MACHINE, notifying users with the supplied MESSAGE, within the specified TIMEOUT interval. Forces closing of all documents without prompting the user if FORCECLOSE is true, and reboots the machine if REBOOT is true. This function works only on WinNT.

Win32::IsWinNT()
[CORE] Returns non zero if the Win32 subsystem is Windows NT.

Win32::IsWin95()
[CORE] Returns non zero if the Win32 subsystem is Windows 95.

Win32::LoadLibrary(LIBNAME)
[EXT] Loads a dynamic link library into memory and returns its module handle. This handle can be used with Win32::GetProcAddress and Win32::FreeLibrary. This function is deprecated. Use the Win32::API module instead.

Win32::LoginName()
[CORE] Returns the username of the owner of the current perl process.

Win32::LookupAccountName(SYSTEM, ACCOUNT, DOMAIN, SID, SIDTYPE)
[EXT] Looks up ACCOUNT on SYSTEM and returns the domain name the SID and the SID type.

Win32::LookupAccountSID(SYSTEM, SID, ACCOUNT, DOMAIN, SIDTYPE)
[EXT] Looks up SID on SYSTEM and returns the account name, domain name, and the SID type.

Win32::MsgBox(MESSAGE [, FLAGS [, TITLE]])
[EXT] Create a dialogbox containing MESSAGE. FLAGS specifies the required icon and buttons according to the following table:
        0 = OK
        1 = OK and Cancel
        2 = Abort, Retry, and Ignore
        3 = Yes, No and Cancel
        4 = Yes and No
        5 = Retry and Cancel
        MB_ICONSTOP          "X" in a red circle
        MB_ICONQUESTION      question mark in a bubble
        MB_ICONEXCLAMATION   exclamation mark in a yellow triangle
        MB_ICONINFORMATION   "i" in a bubble

TITLE specifies an optional window title. The default is ``Perl''.

The function returns the menu id of the selected push button:

        0  Error
        1  OK
        2  Cancel
        3  Abort
        4  Retry
        5  Ignore
        6  Yes
        7  No

Win32::NodeName()
[CORE] Returns the Microsoft Network node-name of the current machine.

Win32::RegisterServer(LIBRARYNAME)
[EXT] Loads the DLL LIBRARYNAME and calls the function DllRegisterServer.

Win32::SetCwd(NEWDIRECTORY)
[CORE] Sets the current active drive and directory. This function does not work with UNC paths, since the functionality required to required for such a feature is not available under Windows 95.

Win32::SetLastError(ERROR)
[CORE] Sets the value of the last error encountered to ERROR. This is that value that will be returned by the Win32::GetLastError() function. This functions has been added for Perl 5.6.

Win32::Sleep(TIME)
[CORE] Pauses for TIME milliseconds. The timeslices are made available to other processes and threads.

Win32::Spawn(COMMAND, ARGS, PID)
[CORE] Spawns a new process using the supplied COMMAND, passing in arguments in the string ARGS. The pid of the new process is stored in PID. This function is deprecated. Please use the Win32::Process module instead.

Win32::UnregisterServer(LIBRARYNAME)
[EXT] Loads the DLL LIBRARYNAME and calls the function DllUnregisterServer.
December 26

MFC中常用类, 宏, 函数介绍(转载)

 
//-----------------------------------------
 
常用类
CRect:用来表示矩形的类,拥有四个成员变量:top left bottom right。分别表是左上角和右下角的坐标。可以通过以下的方法构造:
  • CRect( int l, int t, int r, int b ); 指明四个坐标
  • CRect( const RECT& srcRect ); 由RECT结构构造
  • CRect( LPCRECT lpSrcRect ); 由RECT结构构造
  • CRect( POINT point, SIZE size ); 有左上角坐标和尺寸构造
  • CRect( POINT topLeft, POINT bottomRight ); 有两点坐标构造

下面介绍几个成员函数:

  • int Width( ) const; 得到宽度
  • int Height( ) const; 得到高度
  • CSize Size( ) const; 得到尺寸
  • CPoint& TopLeft( ); 得到左上角坐标
  • CPoint& BottomRight( ); 得到右下角坐标
  • CPoint CenterPoint( ) const; 得当中心坐标
此外矩形可以和点(CPoint)相加进行位移,和另一个矩形相加得到“并”操作后的矩形。

CPoint:用来表示一个点的坐标,有两个成员变量:x y。 可以和另一个点相加。

CString:用来表示可变长度的字符串。使用CString可不指明内存大小,CString会根据需要自行分配。下面介绍几个成员函数:

  • GetLength 得到字符串长度
  • GetAt 得到指定位置处的字符
  • operator + 相当于strcat
  • void Format( LPCTSTR lpszFormat, ... ); 相当于sprintf
  • Find 查找指定字符,字符串
  • Compare 比较
  • CompareNoCase 不区分大小写比较
  • MakeUpper 改为小写
  • MakeLower 改为大写

CStringArray:用来表示可变长度的字符串数组。数组中每一个元素为CString对象的实例。下面介绍几个成员函数:

  • Add 增加CString
  • RemoveAt 删除指定位置CString对象
  • RemoveAll 删除数组中所有CString对象
  • GetAt 得到指定位置的CString对象
  • SetAt 修改指定位置的CString对象
  • InsertAt 在某一位置插入CString对象

常用宏

RGB

TRACE

ASSERT

VERIFY

常用函数

CWindApp* AfxGetApp();

HINSTANCE AfxGetInstanceHandle( );

HINSTANCE AfxGetResourceHandle( );

int AfxMessageBox( LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0 );用于弹出一个消息框

 

 
There are no photo albums.
No list items have been added yet.