Yesterday i worked on the little side project where i had to add dynamic text into my text area by clicking couple of icons and then just continuing to type, but for some reason all dynamic text was added after the cursor so after adding other text by typing, it would type before the dynamic text.
i spent couple of mins googling it and seen that no one found the answer to it so here it is
this is a simple guest book comment window.
This is what i looks like now
here is the code to make it work the way we want it
mc1.addEventListener(MouseEvent.CLICK, addSmile);
mc2.addEventListener(MouseEvent.CLICK, addSmile);
mc3.addEventListener(MouseEvent.CLICK, addSmile);
mc4.addEventListener(MouseEvent.CLICK, addSmile);
mc5.addEventListener(MouseEvent.CLICK, addSmile);
mc6.addEventListener(MouseEvent.CLICK, addSmile);
post_btn.addEventListener(MouseEvent.CLICK, sendData);
function addSmile(e:MouseEvent):void
{
if(e.target == mc1)
{
content_txt.appendText(" =P ");
}
if(e.target == mc2)
{
content_txt.appendText(" =) ");
}
if(e.target == mc3)
{
content_txt.appendText(" =O ");
}
if(e.target == mc4)
{
content_txt.appendText(" =( ");
}
if(e.target == mc5)
{
content_txt.appendText(" =D ");
}
if(e.target == mc6)
{
content_txt.appendText(" =*) ");
}
content_txt.setSelection(content_txt.length, content_txt.length);
}
function sendData(e:MouseEvent):void
{
var ureq:URLRequest = new URLRequest("link to parser.php");
ureq.method = URLRequestMethod.POST;
var sendVars:URLVariables = new URLVariables();
sendVars.content = content_txt.text;
sendVars.title = title_txt.text;
ureq.data = sendVars;
navigateToURL(ureq, "_self");
}
The content_txt.setSelection(content_txt.length, content_txt.length); line
moves the cursor to the end by selecting the last index of the text. and allows you to continue typing as you normally would.
Hope it helps
Saturday, August 22, 2009
Tuesday, August 4, 2009
Custom FLV Player in Flash ACTIONSCRIPT 3.0 Part 1
Today we'll be building a Flash FLV player from scratch. This video will be able to play videos from sites such as youtube and veoh as long as you know the link to the flv.
Video At the botom of this post.
Anyway lets start off
Create a new Actionscript 3.0
var video:Video;
var netCon:NetConnection;
var stream:NetStream;
function loadVideo(url:String):Video
{
video = new Video();
netCon = new NetConnection();
netCon.connect(null);
stream = new NetStream(netCon);
stream.play(url);
var client:Object = new Object();
client.onMetaData = onMetaEvent;
stream.client = client;
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
video.attachNetStream(stream);
return video;
}
function onMetaEvent(e:Object):void
{
//Leave Blank for now
}
function netStatus(e:NetStatusEvent):void
{
video.width = stage.stageWidth;
video.height = stage.stageHeight;
}
stage.addChild(loadVideo("sample.flv")); //loadVid accepts 1 param, and its the URL to the flv video.
Video At the botom of this post.
Anyway lets start off
Create a new Actionscript 3.0
var video:Video;
var netCon:NetConnection;
var stream:NetStream;
function loadVideo(url:String):Video
{
video = new Video();
netCon = new NetConnection();
netCon.connect(null);
stream = new NetStream(netCon);
stream.play(url);
var client:Object = new Object();
client.onMetaData = onMetaEvent;
stream.client = client;
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
video.attachNetStream(stream);
return video;
}
function onMetaEvent(e:Object):void
{
//Leave Blank for now
}
function netStatus(e:NetStatusEvent):void
{
video.width = stage.stageWidth;
video.height = stage.stageHeight;
}
stage.addChild(loadVideo("sample.flv")); //loadVid accepts 1 param, and its the URL to the flv video.
Friday, June 26, 2009
How to Read and Parse JSON files
In this tutorial we are going to use Action script 3.0 to load in the JSON file and decode it, make it intoActionScript 3.0 readable Flash object and then using that object we can access different parts of the JSON file within our Flash application.
What is a JSON file?
JSON file is a JavaScript Object Notation (Jason) Is Somewhat like XML But parsing it is much easier than XML and dealing with Parent/Child nodes and so on.
Our json file is gonna be a file from mochi site, a game site.
(you are not limited to just files, you can load in json RSS feeds also as well as files).
You'll need the as3corelib classes. so go and download them, put them in your global class folder(com.adobe..)
when you have that done. lets get into it.
Open your Adobe Flash cs3 or cs4, ActionScript 3.0 document
Open actionscript pannel
import com.adobe.serialization.json.*;
var jsonInfo:Object; //This is where we'll store the data we load from json file
var uReq:URLRequest = new URLRequest("myJsonFile.json"); //pass in the URL to the JSON file or JSON RSS feed. (for feeds use http://somesitefeed)
var uLoader:URLLoader = new URLLoader();
uLoader.addEventListener(Event.COMPLETE, jsonLoaded);
uLoader.load(uReq); //pass in the URLRequest
function jsonLoaded(e:Event):void
{
jsonInfo = JSON.decode(uLoader.data);
trace(jsonInfo.games); //this is gonna return 2 objects.
trace(jsonInfo.games[0]); //this is gonna return an object.
trace(jsonInfo.games[0].slug); //This is gonna return the name of
//the game at 1st index "gridlock-buster"
}
I'll include the flv, .json and .swf file.
Hope it helps
Download FLV(zipped)
What is a JSON file?
JSON file is a JavaScript Object Notation (Jason) Is Somewhat like XML But parsing it is much easier than XML and dealing with Parent/Child nodes and so on.
Our json file is gonna be a file from mochi site, a game site.
(you are not limited to just files, you can load in json RSS feeds also as well as files).
You'll need the as3corelib classes. so go and download them, put them in your global class folder(com.adobe..)
when you have that done. lets get into it.
Open your Adobe Flash cs3 or cs4, ActionScript 3.0 document
Open actionscript pannel
import com.adobe.serialization.json.*;
var jsonInfo:Object; //This is where we'll store the data we load from json file
var uReq:URLRequest = new URLRequest("myJsonFile.json"); //pass in the URL to the JSON file or JSON RSS feed. (for feeds use http://somesitefeed)
var uLoader:URLLoader = new URLLoader();
uLoader.addEventListener(Event.COMPLETE, jsonLoaded);
uLoader.load(uReq); //pass in the URLRequest
function jsonLoaded(e:Event):void
{
jsonInfo = JSON.decode(uLoader.data);
trace(jsonInfo.games); //this is gonna return 2 objects.
trace(jsonInfo.games[0]); //this is gonna return an object.
trace(jsonInfo.games[0].slug); //This is gonna return the name of
//the game at 1st index "gridlock-buster"
}
I'll include the flv, .json and .swf file.
Hope it helps
Download FLV(zipped)
Labels:
action script 3.0,
json file
Friday, June 12, 2009
Create a simple Login App for your site
So you have a site and you have some page only you know about and only way to get to it is by typing in the UserID and password.
Preview. LoginID: Alen Password:TranquilX7
I'll show you how to make a simple Login with flash and actionscript 3.0
This script isnt secure and can be cracked by hackers so if you are thinking of using it for bigger sites, check back on this site where i'll write a secure login tutorial on how to make login script using PHP and MYSQL. but for starters this will do.
So lets get into it.
Start a new ActionScript3.0 document.
Set Stage size and frame rate to what you want to use.
for this tutorial set stage size to 200 x 80, frame rate 15.
Now that we have that done. Drag 2 Imput text boxes on the stage from Components.
set them where you want them to be.
drag 2 buttons on the stage. somewhere near the imput text and name one clear and another one submit.
Time to give those 4 components instance names.
userID text field give it instance name of user_txt
password text field, give it instance name of pass_txt
submit and clear buttons, instance name of submin_btn and clear_btn.
now on to code. Actionscript 3.0
Download FLA
Login script, flash login tutorial, flash tutorials, actionscript 3.0 login script
Preview. LoginID: Alen Password:TranquilX7
I'll show you how to make a simple Login with flash and actionscript 3.0
This script isnt secure and can be cracked by hackers so if you are thinking of using it for bigger sites, check back on this site where i'll write a secure login tutorial on how to make login script using PHP and MYSQL. but for starters this will do.
So lets get into it.
Start a new ActionScript3.0 document.
Set Stage size and frame rate to what you want to use.
for this tutorial set stage size to 200 x 80, frame rate 15.
Now that we have that done. Drag 2 Imput text boxes on the stage from Components.
set them where you want them to be.
drag 2 buttons on the stage. somewhere near the imput text and name one clear and another one submit.
Time to give those 4 components instance names.
userID text field give it instance name of user_txt
password text field, give it instance name of pass_txt
submit and clear buttons, instance name of submin_btn and clear_btn.
now on to code. Actionscript 3.0
user_txt.text = ""; //clears the userID textfield every time it loads
user_txt.maxChars = 12; //sets the max number of characters to 12.
pass_txt.text = ""; //clears the password field every time it loads
pass_txt.displayAsPassword = true; //changes all letters/numbers to ***
pass_txt.maxChars = 12; // sets the max characters allowed to 12
//add events to buttons. when they are clicked one of those events will trigger
clear_btn.addEventListener(MouseEvent.CLICK, clearFields);
submit_btn.addEventListener(MouseEvent.CLICK, submitForm);
//create the event for clear field button. this resets the field to empty
function clearFields(e:MouseEvent):void
{
user_txt.text = "";
pass_txt.text = "";
}
//create the event for submit button, this will check for user id and pass and if right it will //send you to the right URL that you put in. this can check for more than one user. //if you have a small site and few users they can access their page by putting id and name that //matches and they'll be sent to the right page.
function submitForm(e:MouseEvent):void
{
//checks if the user_txt.text is equal to "Alen" and if pass_txt.text is squal to "TranquilX7" // && means And. both of these need to return as true for this to be true. //if both are true then we are sent to the URL
if(user_txt.text == "Alen" && pass_txt.text == "TranquilX7")
{
//navigateToURL() needs 2 params, URLRequest, thats where you'll be taken if login is success //and in what window to open it. "_blank" opens new URL in new window. other few are //"_same", "_top", "_self", "_parent".
navigateToURL(new URLRequest("http://tranquilx7-flashmade-ez.blogspot.com"), "_blank");
}
//if the User id and pass dont match. it will do what ever is in this else statament. // here we just trace out that the login failed and we clear the fields so new ID and pass can be //entered
else
{
trace("login failed, please try again");
user_txt.text = "";
pass_txt.text = "";
}
}
Download FLA
Login script, flash login tutorial, flash tutorials, actionscript 3.0 login script
Labels:
action script 3.0,
login script
Wednesday, June 10, 2009
Loading Images From library in Actionscrip 3.0
If you were using ActionScript 2.0(AS2.0) you may have noticed that the differance is huge between AS2.0 and AS3.0 and one of thise big differances is loading images.
In actionscript 2.0 loading Images from Library is much more easier.
for example.
_root.attachMovie("myImage", "MyImage1", this.getNextHighestDepth, {_x:200, _y:200});
This line of code will add the image with the linkage ID of "myImage",
it will give it a new instance name of MyImage1.
Put it on the top of everything else on the stage, set its x and y to 200, 200.
Now in ActionScript3.0 it gets a lil harder. lets take a look at it shall we
var bmd:BitmapData = new myImage(0, 0);
var img:Bitmap = new Bitmap(bmd);
stage.addChild(img);
img.x = 200;
img.y = 200;
see the difference? in AS3.0 you have to create a bitmapData, passing in the linkageID of your image. and it will look for 2 params. which is the x and y of the image you want to load in. just leave it at 0, 0
next you have to create a bitmap and make a new instance of it. and pass in the BitmapData as a param.
next add the Bitmap to the stage using addChild(); passing in the Bitmap
after the image is on the stage, we set its x and y.
Actionscript 3.0 load images from library Load jpg images from library, load pngs from library,
Dynamicly load images from library, using bitmap data
In actionscript 2.0 loading Images from Library is much more easier.
for example.
_root.attachMovie("myImage", "MyImage1", this.getNextHighestDepth, {_x:200, _y:200});
This line of code will add the image with the linkage ID of "myImage",
it will give it a new instance name of MyImage1.
Put it on the top of everything else on the stage, set its x and y to 200, 200.
Now in ActionScript3.0 it gets a lil harder. lets take a look at it shall we
var bmd:BitmapData = new myImage(0, 0);
var img:Bitmap = new Bitmap(bmd);
stage.addChild(img);
img.x = 200;
img.y = 200;
see the difference? in AS3.0 you have to create a bitmapData, passing in the linkageID of your image. and it will look for 2 params. which is the x and y of the image you want to load in. just leave it at 0, 0
next you have to create a bitmap and make a new instance of it. and pass in the BitmapData as a param.
next add the Bitmap to the stage using addChild(); passing in the Bitmap
after the image is on the stage, we set its x and y.
Actionscript 3.0 load images from library Load jpg images from library, load pngs from library,
Dynamicly load images from library, using bitmap data
Labels:
3.0,
action script 2.0,
action script 3.0,
actionscript 3.0
Subscribe to:
Posts (Atom)
