myXML.load("update.xml?" + Math.random());
Tuesday, September 29, 2009
Cache Problem with IE
this problem is mostly found with IE, while we update the XML file, the flash file still remains the same , due to cache, thus to solve this problem we can use math.random method, and it really works, i tried this a million times.
Wednesday, September 23, 2009
Add Style Sheet to Dynamic Text
sample css for dynamic text
.bodyCopy
{
font-family: Arial;
font-size: 12px;
color: #666666;
line-height: 28px;
}
{
font-family: Arial;
font-size: 12px;
color: #666666;
line-height: 28px;
}
ActionScript
var format = new TextField.StyleSheet();
var path = "main_styles.css";
format.load(path);
format.onLoad = function(success) {
if (success) {
output.styleSheet = format;
var path = "main_styles.css";
format.load(path);
format.onLoad = function(success) {
if (success) {
output.styleSheet = format;
} else{
trace("style sheet not loaded")
}
}
Wednesday, September 16, 2009
Flash ActionScript 2.0 Dynamic Vertical Menu
we all know about XML and its uses over Internet. Now a days, requirements comes mostly for dynamically created flash , i mean to say xml embeded flash file. As for now I am going to show how to create such files. In my example I would show how to create menu item dynamically, embeding XML with flash. So lets start....
-
-
-
-
-
1) First we need to create a XML file maintaining this following formate, you can know more about XML from this link http://www.w3schools.com/xml/default.asp . My XML file should look like this.
2) Open Flash proffesional 8 or upperversion, create a new file, save the file with the XML file you got.
3) Create a rectangel , width:120, and height:20, and then convert it into movieclip and name it as "menuitem"
4) Double click on this particular movieclip and create a new layer, go to the first frame of the new layer and then create a dynamic text field and give it an instance name "name"
5) Come over to the stage and press CTLR + L or you can go to windows>library. you can find the movieclip named menuitem there, right click over the movieclip, chose properties, there yon find Linkage option.
Check for Export for Actionscript, the name for Identifier and Export for first frame will get filled, dont change them, keep it as it is. Press ok and then come to the stage. you can find the menuitem movieclip, remove it from the stage.
6) Select the frist frame and press F9, the action panel will open up. From here on we continue with the actionscript 2.0. Generates a list of menu items , given the inputted parameters. This makes the main menu.
Loading and Interpreting XML
xmlNode = xmlObject.firstChild;
for (var i = 0; i <>
xmlNode.childNodes[i].nodeName;
xmlNode.childNodes[i].attributes.name;
xmlNode.childNodes[i].attributes.action;
xmlNode.childNodes[i].attributes.variables;
}
Get XML
menu_xml = new XML();
menu_xml.ignoreWhite = true;
menu_xml.onLoad = function(ok){
if (ok){
Createmainmenu(10, 10, 0, this);
}
};
menu_xml.load("myXMLfile.xml");
Generating Menu
if (node_xml.childNodes[i].nodeName == "menu"){
curr_item.node_xml = curr_node;
curr_item.onRollOver = curr_item.onDragOver = function(){
var x = this._x + this._width - 5;
var y = this._y + 5;
GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml);
};
}else{
curr_item.arrow._visible = false;
curr_item.onRollOver = curr_item.onDragOver = function(){
curr_menu.submenu_mc.removeMovieClip();
};
}
Action
Actions = Object();
Actions.gotoURL = function(urlVar){
getURL(urlVar, "_self");
};
At the End the Script will look like this
GenerateMenu = function(container, name, x, y, depth, node_xml) {
var curr_node;
var curr_item;
var curr_menu = container.createEmptyMovieClip(name, depth);
for (var i=0; i<4;>
curr_item = curr_menu.attachMovie("menuitem","item"+i+"_mc", i);
curr_item._x = x;
curr_item._y = y + i*curr_item._height;
curr_item.trackAsMenu = true;
curr_node = node_xml.childNodes[i];
curr_item.action = curr_node.attributes.action;
curr_item.variables = curr_node.attributes.variables;
curr_item.name.text = curr_node.attributes.name;
curr_item.onRollOut = curr_item.onDragOut = function(){
var col = new Color(this.background);
col.setTransform({ra:100,rb:0,ga:100,gb:0,ba:100,bb:0});
};
curr_item.onRelease = function(){
Actions[this.action](this.variables);
CloseSubmenus();
};
}
};
Createmainmenu = function(x, y, depth, menu_xml){
GenerateMenu(this, "mainmenu_mc", x, y, depth, menu_xml.firstChild);
mainmenu_mc.onMouseUp = function(){
if (mainmenu_mc.submenu_mc && !mainmenu_mc.hitTest(_root._xmouse, _root._ymouse, true)){
CloseSubmenus();
}
};
};
CloseSubmenus = function(){
mainmenu_mc.submenu_mc.removeMovieClip();
};
Actions = Object();
Actions.gotoURL = function(urlVar){
getURL(urlVar, "_self");
};
Actions.newMenu = function(menuxml){
myXMLfile_xml.load(menuxml);
};
myXMLfile_xml = new XML();
myXMLfile_xml.ignoreWhite = true;
myXMLfile_xml.onLoad = function(ok){
if (ok){
Createmainmenu(10, 10, 0, this);
trace( "message area");
}else{
trace("error: XML not successfully loaded");
}
};
myXMLfile_xml.load("myXMLfile.xml");
Flash ActionScript setInterval
Many a times we feel the need to set time intervel between frams so this is an example of it. Lets get started.
1) first we take a variable displayTime and that will be = to the duration
var displayTime = 5;
in here 5 is for 5 seconds hold, if you want then you can increase or decrease the time as you want.
2) Its time for us to create the function
so the name of the function is countDown
var displayTime = 5;
countDown=function(){
}
3) Next is to verify weather the function get loaded sucessfully and display the message after 5 sec.
var displayTime = 5;
countDown=function(message){
}
4) we create a loop function now so that the function starts countion reverse as for ex 5sec, 4sec, 3sec, 2sec, 1sec, and finally go
var displayTime = 5;
countDown=function(message){
displayTime--;
}
5) how would the function know weather it has finished counting or not , thus its time for condition.
var displayTime = 5;
countDown = function(message)
{
displayTime--;
if (displayTime == 0){
}
}
6) finallly you need to stop the loop function or else it would continue the loop function and you get confused, we use clearInterval to end the timer.
var displayTime = 5;
countDown = function(message)
{
displayTime--;
if (displayTime == 0){
clearInterval(timer);
trace("this action you need to paste here")
}
}
timer = setInterval(countDown, 1000);
the whole script would look like this
var displayTime = 5;
countDown = function(message)
{
displayTime--;
if (displayTime == 0){
clearInterval(timer);
trace("this action you need to paste here")
}
}
timer = setInterval(countDown, 1000);
Saturday, September 5, 2009
Web 2.0 Format layout
Subscribe to:
Posts (Atom)