- Mix Services
- Sound Import Export
I got he hint from playFile() documentation for Director. It mentions the use of "Correct Mix Xtra" to play sound properly.
oValidator = new(script "ValidationUtil")Predefined validators (functions) can be called by their string name using call(...) method.
isValid = oValidator.validate([ \
["txtField1", ["NonEmptyValidator"],"Please enter textField1"], \
["txtSSN", ["LengthValidator", 4],"Please enter 4 digit ssn"], \
["txtSSN", ["NumberValidator"],"Please enter a numeric value"]
)
-----------------------------------------------------New Validators can be added as an when needed. PRegEX_search(...) comes from PRegEx Xtra. Fortunately, it is free to download. This framework handles error notifications by showing alert messages whenever validation fails. Neat isn't it.
-- This class manages all the validation stuff --
-- @author : Raghavendra Kotikalapudi --
-- @email : ragha.unique2000@gmail.com --
-----------------------------------------------------
--Currently works only for text fields..
--Checks for validation on the given validator..
on isValidOnValidator me, memberName, lstValidatorAndParams
val = sprite(memberName).text
--Extract validator name..
validator = lstValidatorAndParams[1]
otherParams = lstValidatorAndParams
--Remove validator name...it now has params only.
otherParams.deleteAt(1)
--Achieves dynamic function calling..
return call(symbol(validator), me, val, otherParams)
end
--This is the main function to be called.
on validate me, lstMembersAndValidators
ret = true
repeat with lst in lstMembersAndValidators
if isValidOnValidator(me, lst[1], lst[2]) = false then
alert(lst[3])
ret = false
exit repeat
end if
end repeat
return ret
end
--Validates non emptiness..
on NonEmptyValidator me, str, lstOptionalParams
if voidP(str) then
return false
else if length(str) = 0 then
return false
else
return true
end if
end
--Validates of length of str in in the range (low, hi) inclusive
--lstOptParams has low, high pair
on LengthRangeValidator me, str, lstOptionalParams
len = length(str)
if len >= lstOptionalParams[1] and len <= lstOptionalParams[2] then return true else return false end if end --Validates for non existence of special symbols.. --i.e, str can contain a-z, A-Z or 0-9 on NoSpecialSymbolsValidator me, str, lstOptionalParams foundCount = PRegEx_Search([str], "~+|`+|!+|@+|#+|\$+|%+|\^+|&+|\*+|\(+|\)+|\{+|\}+|\[+|\]+|\++|\\+|\|+|:+|;+|/+|\<+|\>+|\?+|,+")
--If special char is found, validate to false
if foundCount > 0 then
return false
else
return true
end if
end
--Validates if the given str is a valid name or not, i.e., it should not contain
--special symbols or 0-9
on NameValidator me, str, lstOptionalParams
val = NoSpecialSymbolsValidator(me, str, lstOptionalParams)
if val = false then
return false
else
foundCount = PRegEx_Search([str], "[0-9]+")
--If number if found..
if foundCount > 0 then
return false
else
return true
end if
end if
end
-------------------------------------------------------------Sample usage is illustrated below:
--------------Report generation Utility class----------------
-------------------------------------------------------------
--Finds and replaces the first occurrence of 'aLookForString' with 'aReplaceString'
--in 'aString' and returns the new string
on findAndReplace me, aString, aLookForString, aReplaceString
n = aLookForString.length -1
is_ok = false
repeat while is_ok = false
place = offset(aLookForString, aString)
if (place = 0) then
is_ok = true
exit repeat
else
put aReplaceString into char place to (place+n) of aString
exit repeat
end if
end repeat
return aString
end
--Saves the text in given filename
on saveText me, text, filename
-- create the FileIO instance
fileObj = new(xtra "FileIO")
-- delete existing file, if any
openFile (fileObj,filename,2)
delete(fileObj)
-- create and open the file
createFile(fileObj,filename)
openFile(fileObj,filename,2)
-- check to see if file opened ok
if status(fileObj) <> 0 then
err = error(fileObj,status(fileObj))
alert "Error:"&&err
return FALSE
end if
-- write the file
writeString(fileObj,text)
-- close the file
closeFile(fileObj)
return TRUE
end
--Reads the text from a given filename
on readFromFile me, filename
-- create the FileIO instance
fileObj = new(xtra "FileIO")
-- open the file
openFile(fileObj,filename,1)
-- check to see if file opened ok
if status(fileObj) <> 0 then
err = error(fileObj,status(fileObj))
alert "Error:"&&err
return ""
end if
-- read the file
text = readFile(fileObj)
-- close the file
closeFile(fileObj)
--return the text
return text
end
oUtilClass = new(script "UtilClass")
--Read html from the template
html = oUtilClass.readFromFile(the moviepath & "\\Templates\\summary report.htm")
--Fill in data..
global strSelectedDate
html = oUtilClass.findAndReplace(html, "$1", someVar)
html = oUtilClass.findAndReplace(html, "$2", anotherVar)
filename = the moviepath & "print.html"
oUtilClass.saveText(html, filename)
--Invoke through a browser..
fileXtra4Obj = xtra("FileXtra4").new()
fileXtra4Obj.fx_FileRunApp(the moviepath & "run.bat")
<html>
Some blah blah..
Name: $1 </br>
Age : $2 </br>
<table>
<tr>
<td> Subject </td>
<td> Marks </td>
</tr>
<tr>
<td> Some subject </td>
<td> 85 </td>
</tr>
</table>
</html>
<tr>Here's the big idea. Whenever you build a table, read in the row data template, fill it and append it to the main html. Here's an example. Highlighted code achieves dynamic table generation behavior.
<td> $1 </td>
<td> $2 </td>
</tr>
--Read html from the templateI know, it looks complicated. But atleast this is transparent and you exactly know whats going on. Moreover, this approach gives you unlimited formatting options, works and is free. Once you get a hand of it, it'll seem pretty simple.
html = oUtilClass.readFromFile(the moviepath & "\\Templates\\template1.htm")
--Fill in data..
global strSelectedDate
html = oUtilClass.findAndReplace(html, "$1", name)
html = oUtilClass.findAndReplace(html, "$2", age)
tableRows = ""
--Read in the row template..
rowTemplate = oUtilClass.readFromFile(the moviepath & "\\Templates\\template1_rows.htm")
--Generate table rows..
repeat with row=1 to numRows
tableRow = rowTemplate
tableRow = oUtilClass.findAndReplace(tableRow , "$1", subject)
--Append data to tableRows..
tableRows = tableRows & rowTemplate
end repeat
--Fill in table data..
html = oUtilClass.findAndReplace(html, "$3", tableRows)
filename = the moviepath & "print.html"
oUtilClass.saveText(html, filename)
fileXtra4Obj = xtra("FileXtra4").new()
fileXtra4Obj.fx_FileRunApp(the moviepath & "run.bat")