Setting the @Embed source with an absolute path (based on flex_src root) :
<mx:Button icon="@Embed(source='/assets/blue_delete.png')" />
Technology, activities, etc.
<mx:Button icon="@Embed(source='/assets/blue_delete.png')" />
I needed to store MD5 hashed passwords in the database and was delighted to find the as3corelib already contains the necessary libraries. While there are many more features, I only needed the MD5 Hash function so I only copied in the com.adobe.crypto.MD5 and com.adobe.utils.* files. With the .as files added to my Flex project, hashing the password was a simple as calling:
MD5.hash( passwordComp.getPassword() );
I verified that it returns the same hash as the MySQL MD5 function
UPDATE user_table SET password = MD5(‘change_me’) WHERE username = ‘sandman’
I was having trouble with positioning a wide popup window that was in a component nested several containers deep. The PopUpManager.centerPopUp method would center on the container and push the window off the right edge of the screen. To correct this, I moved the popup over 100 pixels using:
popup.x = popup.x – 100;
That worked, but the problem would come back if the window grew wider. Bush league. To make it a bit more reliable, I changed to use the mouseEvent localX/Y properties. Note you have to convert the “local” coordinates to “global”:
private function showPopup(event:MouseEvent):void
{
pop = EnotaryRegReturnPopup(PopUpManager.createPopUp(this,EnotaryRegReturnPopup,true));
pop.title = "Please select return reasons.";
pop.showCloseButton =true;
pop.enotaryRegReturnList = this.enotaryRegReturnList;
pop.buildUnselectedReturns();
// position the window next to the "add" button
var pt:Point = new Point(event.localX, event.localY);
pt = event.target.localToGlobal(pt);
pop.x = pt.x - pop.width;
pop.y = pt.y;
pop.addEventListener("close",removeMe);
pop["cancelButton"].addEventListener("click", removeMe);
pop["okButton"].addEventListener("click",processReturns);
}
I was surprised by the delete functionality in DataTable. It was my understanding that when you call DataRow.Delete it marks the row for deletion, but waits for a DataTable.AcceptChanges call before actually removing them, but when I tried to delete inside a For Each dr as DataRow in dt.Rows I was getting an error “Collection was modified”. Thankfully I ran across a thread that suggested walking backwards through the collection to avoid those types of errors. I ended up with this to solve my problem:
Do While i >= 0
If dt.Rows(i)("KEEP_ME"))) = False Then dt.Rows(i).Delete()
i -= 1
dt.AcceptChanges()
I needed to rename a directory of files to truncate the file names to the first 5 characters (plus the file extension). I found one example that showed how two write a FOR loop that broke out the filename and extension and passed it to a second BAT file:
for /f %%a IN (’dir /b *.txt’) do call runner.bat %%~na %%~xa
And using a second example that covered DOS string manipulation, I put together this batch file that accepts two parameters and does a substring to get the first 5 characters of the first parameter:
set file=%1
set file=%file:~0,5%
ren %1%2 %file%%2
I recently created a page that gave the user the option of initiating a long-running batch process. The batch required repeatedly calling external web services that would have taken far too long for a user to wait for the traditional page processing model. But, by using ASP.NET asynchronous execution to initiate the batch process on a separate thread, the page response is excellent. I started by working through this excellent tutorial on asynchronous execution, but quickly ran into problems when I began calling web services. Creating an asynchronous process involves writing a method that can execute without needing anything from the HttpContext (Application, Page, Session, Cache, Configuration, etc.) since this is not available when you use BeginInvoke to run your subroutine. This presented me with an issue since my project had a library that we used to setup web service instances (with WSE security), but that library relied on the HttpContext’s Application object. To work around this limitation, I created a private inner class that encapsulated the web service references.
Private Class WebSvcInstances
Public FSI As MyWseSVc1 = GetMyWseSVc1
Public PSI As MyWseSVc2 = GetMyWseSVc2
End Class
The inner class was passed into the batch method while the Application object was still available and providing the objects the batch would need later.
To start off, create the subroutine you want to initiate asynchronously:
Private Sub InitiateBatch(ByVal wsRefs As WebSvcInstances)
Create a Delegate in your code behind with the same signature as the subroutine:
Private Delegate Sub Batch_Delegate(ByVal wsRefs As WebSvcInstances)
Then you can initiate your subroutine in a page event like so:
Dim batchDelegate As InitiateBatch_Delegate
Dim wsRefs As New WebSvcInstances
batchDelegate = New InitiateBatch_Delegate(AddressOf InitiateBatch)
Dim asyncResult As IAsyncResult
asyncResult = batchDelegate.BeginInvoke(wsRefs, Nothing, Nothing)
You can read up on BeginInvoke to learn more about the callback features. I didn’t need to be notified when the execution finished, so I just set those to Nothing