31 August, 2009

Interview Questions - Part 2

Interview Questions
--------------------------
16. What is Global.asasx file?
a. This file contains application and session level events. It is an optional file. It is placed in the
root directory of the application.

17. what is the difference between inline and code behind models?
a. In inline model server code is written along with the html code.
in code behind model server side code is written in separate file having .aspx extension.

18. How many types of validation controls are there in asp.net?
there are 6 types of validation controls are there.
1.RequiredFieldValidator:
Used to ensure that there is an entry for a specified field.
2. CompareValidator:
Used to check users entry with a constant value or value of another control
3. RangeValidator:
Used to check whether users value is with in the specified range or not.
4. RegularExpressionValidator:
Used to check users entry against a pattern specified by regular expression.
5. CustomValidator:
Enables a user to specify his/her validation logic
6. ValidationSummary:
Used to display all the error messages at one place in a web page.

19. which directive do we use to add a custom or user control to a web page?
a. We use @Register control.

20. What is the extension and namespace for user controls?
a. User controls have .ascx extension and namespace is System.Web.UI.Usercontrol

21. What are master pages?
a. Master pages provide a uniform layout for all pages in your application. They are used to
create same look and feel for all pages.they provide a template which can be used by any
number of pages in an application. They have .master extension.

22. Is it possible to nest master pages?
a. Yes.

23. What is a wizard control?
a. This provides a way to create a sequence of steps which can be used by the user. This
control is useful in suituations where you want to split the information in to steps.
for ex. When you are registering in to any web site we can divide the information
collection process from the user in to 3 steps, step1 for login information, step 2 for
personal inrmation and step 3 for address information.

24. what is the method used to set focus on any control?
a. We use Focus() method.

25. what is smart navigation?
a. 1. It maintains same scroll position during postbacks.
2. used to keep element focus during navigation
3. used to minimise flash during navigation
4. only the most recent web page state is retained in the browsers history folder.

30 August, 2009

Interview Qusetions - Part 1

Interview Questions
---------------------------

1. What is a private assembly?
a. An assembly which is used by only one application and which is placed in the installation directory of an application.

2. what is MSIL?
a. When we compile a c# program or any other program written in .net complaint languages, the source code is compiled in to MSIL. It is an instruction set in to which all .net prgrams are compiled and which is used by the CLR. It contains instruction for loading, storing, initializing, and calling methods.

3. What is CTS?
a. CTS means common type system. It defines how types are declared, used and managed in the runtime. This supports a variety of types and operations found in most of the programming languages and therefore calling one language from another does not require type convertions.

4. What is CLS?
a. CLS means common language specification. This enables interoperability in the .net platform.

5. What is JIT?
A. It is a compiler that converts MSIL to native code.

6. why do we use namespaces?
a. Namespaces are used to organise the code and to create globally unique types to avoid name collisions.

7. What is web farm?
a. Asp.net runs with in a process known as asp.net worker process. All asp.net functionality runs with in the scope of this process. A regular web server contains only a single asp.net worker process. A web farm contains multiple asp.net worker processes. Generally normal(small) web sites uses a single web server to satisfy the user requests. but a web farm(larger web sites) uses one or more seb servers to satisfy the user requests.

8. What is Globalization?
a. It is the process of design and development of applications that serve multiple cultures.

9. What is Localization?
a. It is a process of customizing an application for a given culture and locale.

10. What is a Thread?
a. A thread is a basic unit to which operating system allocates processor time. One process can have more than one thread. Each thread maintains exception handlers, scheduling priorities, and a set of structures the system uses to save the thread context until it is scheduled.

11. Differences between managed code and unmanged code?
Managed code:
1.It is executed under CLR.
2.It compiles to intermediate language
3. it provides services like security, exception handling, garbage collection etc
4. It can access both managed and unmanaged data
unmanaged code :
1. It is not executed under CLR.
2. It compiles directly to machine code.
3. It doen not provide security, exception handling, garbage collection etc
4. It can access only unmanaged data.

12. What is a bin directory?
a. It contains precompiled assemblies. this is useful when you need to use code that is possibly written by someone else where you don't have access to the source code but you have a compiled dll instead.

13. What is the use of enableviewstatemac property?
a. This is the attribute of a @page directive. This is used to check whether the view state has been tampered or not.

14. How to change a master page during rntime?
a. This is possible in the PreInit() event by setting MasterPageFile property to .master page.

15. What is serialization?
a. It is a process of saving the state of an object by converting it to a stream of bytes. the object can then be persisted to a file, database, or even memory.

Filling data from Database in to Dataset and then to Datagrid

LOADING DATA FROM DATABASE IN TO DATASET AND BINDING IT TO DATAGRID
---------------------------------------------------------------------------------
Dataset can not directly retrieve data from database. For this purpose we should use DataAdapter. DataAdapter acts as a bridge between database and dataset. This is used to retrieve data from Database into Dataset as well as to Update Database through Dataset.It supports insert, delete, update, select operations. It supports disconnected model.

Now we will see the steps required to fill data from database into dataset and then populate that data into datagrid.
For that

In .aspx page, in <div> section we should write
<div>
<asp:datagrid id="exdatagrid" autogeneratecolumns="true" runat="server">



Here ID represents the id of the datagrid, runat represents that the datagrid is a server control, AutoGenerateColumns automatically creates the columns for the datagrid.

In the .aspx.cs file

1. First we should open a connection
SqlConnection newconn = new SqlConnection(“Server=xxx;InitialCatalog=xxx;
UserId=xx;Password=xxx”);
Newconn.open();

In the above statement server = xxx means we are specifying server name. InitialCatalog means database name from which we want to retrive data. Userid, password are userid and passwords of user for sql server.

2. Next we need to specify the sql statement(required operation)

SqlCommand cmd = new SqlCommand(“select * from xxx”, newconn);

In this statement first argument specifies the sql select statement(required operation) and second statement specifies the connection object. Here xxx represents Table name in database.

3 Now, we need to declare the DataAdapter

SqlDataAdapter da = new SqlDataAdapter(cmd);

In this statement dataadapter contains the command object as its argument to perform the required operation.

4. Now, we need to fill the dataset

ds = new DataSet();
da.Fill(ds);

In these statements first we declare dataset and then using the Fill() method of dataadapter we fill the dataset with the data from Database.

so now dataset is filled with the data from database.

5. Now we fill datagrid with the information/data in the dataset

exdatagrid.DataSource = ds;
exdatagrid.DataBind();

Here exdatagrid is the id of the datagrid we have declared in .aspx page.
DataSource property represents the datasource(means dataset) for the datagrid. DataBind method is used to bind data to the datagrid.

That’s it. We will see the data populated in to the datagrid.

29 August, 2009

DataSet Details

Filling dataset with data from more than one table
------------------------------------------------------------
To Fill dataset with data from more than one table from database and to
bind that data to datagrid we need following code

1. In .aspx file you need to write

&ltdiv>
&ltasp:datagrid id="grid1" runat="server" autogeneratecolumns="True">

&ltasp:datagrid id="grid2" runat="server" autogeneratecolumns="True">



Here we are specifying 2 datagrids to display data from 2 Tables.

2. In .aspx.cs file

1. First we need to open a connection

SqlConnection newconn = new SqlConnection(“Server=xxx;
InitialCatalog=xxx; UserId=xx;Password=xxx”);
Newconn.open();

In the above statement server= xxx means we are specifying server
name.InitialCatalog means database name from which we want to
retrive data. Userid, password are userid and passwords of user
for sql server.

2. Next we need to specify the sql statements(required operation)

DataAdapter da = new SqlDataAdapter("select * from firsttablensme;
Select * from secondtablename”, newconn)

note: here instead of command object we are directly using
DataAdapter.If you want you can use command object also.

In the above statement we are selecting data from two tables.
Newconn is the connection object.

3. Now, we need to fill the dataset

ds = new DataSet();
da.Fill(ds, “firsttablename”);
da.Fill(ds, “secondtablename”);

Here we are using Fill() method of dataadapter to fill the Dataset.

4. Now to bind this data to datagrid we need following code

grid1.DataSource = ds;
grid1.DataSource = ds.Tables[0];
grid1.DataBind();

grid2.DataSource = ds.Tables[1];
grid2.DataBind();

Here DataSource property represents the datasource of the datagrid and
DataBind() method used to bind data to the datagrid.

Note: you can also use caption property of datagrid to specify the table caption
Ex: grid1.caption = “xxx”
here Xxx represents cation for the table displayed by datagrid.

28 August, 2009

C# Interview Questions - Part 10

Interview Questions
----------------------
91. How many types of errors are there?
a ) 2 types
1. Run time errors
2. Compile time errors

92. Give some examples of compile time and runtime errors?
a ) Compile time:
missing semocolons
use of undeclared variables
bad references to objects
runtime:
dividing an integer by zero
using negative size for an array
passing a parameter that is not in a valid range

93. What is an exception?
a ) An exception is a condition that occurs by a run time error in the program

94. What is the base class used for all the exceptions in c#?
a ) It is Exception

95. Why do we use throw keyword?
a ) Throw keyword is used to throw our own exceptions.

96. How many exceptions we can write in throws clause?
a ) We can use multiple exceptions.

97. Can a finally block exists with try block but without a catch block?
a ) Yes

98. Can we have nested try blocks in c#?
a ) yes

99. What is the difference between Write() and WriteLine() methods?
a ) Write() method outputs one or more values to the screen without a newline character
WriteLine() method outputs one or more values to the screen with a newline character

100. What is the difference between Read() and Readline() methods?
a ) Read() method returns a single character as int
ReadLine() method returns a string containing a line of text

27 August, 2009

C# Interview Questions - Part 9

81. why we use the ref keyword?
a ) If you want to pass a parameter by reference you should use the keyword ref

82. If an out parameter is not assigned a value with in the body of the function does that method complile?
a ) No. it won't compile

83. How can you make write a read only property?
a ) A property can made a read only by omitting the set accessor from the property defination.

84. When a static constructor is executed?
a ) It is executed when the class is loaded.

85. How many preprocessor directives exists in c#?
a ) They are #define, #undef, #if, #elif, #else, #endif, #error, #warning, #region, #endregion, #pragma etc

86. When an instance constructor is executed?
a ) It is executed when an instance is created.

87. Where you can assign values to a read only field?
a ) We can assign inside a constructor

88. Why we use the sixeof operator?
a ) If we want to know the size of any data type you can use sizeof operator.

89. What are the disadvantages of distructors in c#?
a ) 1. They are non deterministic. means there is no way to know when an object's destructor will actually execute.
2. Implementation of destructor delays the final removal of an object from memory. means objects that have destructors are removed in 2 passes. in the 1st pass only the destructor will be called with out removing object and then the 2nd pass removes the object, which is time taking and which may effect the performance.

90. What is the default access modifier of an interface members?
a) public

26 August, 2009

C# Interview Questions - Part 8

Interview Questions
-----------------------------

71. Can we declare an abstract method in non abstract class?
a ) No. it can declared only in abstract classes

72. Can we use static or virtual keywords to an abstract method?
a ) No

73. Can an interface extend a class?
a ) No. it can’t extend classes.

74. Is it necessary that the direct base class of a derived class must be at least as accessible as the derived class itself?
a ) Yes.

75. What is the keyword that is used to invoke the constructor method of the super class?
a ) It is the keyword “base”.

76. What is an enumeration?
a ) An enumeration is a user-defined integer type which provides a way for attaching names to numbers.

77. What is boxing?
a ) Conversion of value type to object type (reference type) is known as boxing

78. What is unboxing?
a ) Conversion of object type to value type is known as unboxing.

79. What are the categories of variables that are automatically initialized to their default values?
a ) They are
1. Static variables
2. Instance variables
3. Array elements

80. What is the scope of a variable?
a ) Scope of a variable is the region of code with in which the variable can be accessed.

25 August, 2009

C# Interview Questions - Part 7

Interview Questions
----------------------------
61. Can private virtual methods be overridden ?
a ) No. we can not access private methods in inherited classes.

62. Can we inherit multiple interfaces?
a ) yes. In c# multiple inheritance is achieved through interfaces.

63.How can a method be overloaded?
a ) a method can be overloaded by creating a method with the same name but with different parameter order, data types and number

64. Will finally block get executed if the exception had not occurred?
a ) Yes. Finally block always gets executed regardless of an error.

65. Can multiple catch blocks be executed ?
a ) No. once the appropriate catch code is fired control transfer to the finally block then continues with the rest of the code.

66. What is the accessibility level of a protected variable?
a ) It is available to the classes in the same name space.

67. Can you override private virtual methods
a ) No.

68. Can we inherit multiple interfaces?
a) Yes. We can’t inherit multiple classes but we can inherit multiple interfaces.

69. Can we use virtual keyword to a destructor?
a ) No

70. What is the access level of a internal variable?
a ) current assembly

24 August, 2009

C# Interview Questions - Part 6

Interview Questions
---------------------------
51. What are the types of strings?
a ) 2 types
1. mutable strings
2. immutable strings

52. Is a string is a reference type or value type?
a ) A string is reference type

53. What do you mean by mutable and immutable ?
a ) Mutable means we can alter the characters contained in them.
Immutable means that we can not alter the characters contained in them

54. What are String and StringBuilder classes?
a ) String class is an immutable class and
StringBuilder class is an mutable class

55. Tell me some methods present in StringBuilder class?
a ) They are
Append(),
Insert(),
Remove(),
Replace(),
appendFormat()

56. What is the namespace of StringBuilder class?
a ) System.Text

57. Tell me some methods present in String class?
a ) They are
Copy(),
Equals(),
ConCat(),
Compare(),
Trim(),
Substring(),

58. Can you store multiple data types in System.Array ?
a ) No.

59. What is the class from which an array is created(derived) automatically in c#
a ) System.Array

60. Some common methods of System.Array class?
a ) Clear(), CpoyTo(), GetValue(), Sort(), Reverse() etc.

23 August, 2009

C# Interview Questions - Part 5

41. How can we achieve multiple inheritance in c#?

a ) Using interfaces.

42. An interface is a value type or reference type?

a ) An interface is a reference type.

43. Does an interface extend classes?

a ) No

44. Can we write constructors and destructors for an interface?

a ) No.

45. What are the default modifiers of members of an interface?

a ) Public and abstract

46. What are the differences between an abstract class and an interface?

a ) Abstract class

1. it can contain implementation to some methods.

2. we can apply access modifiers to one or more methods in an abstract class

3. a class can not inherit more than one abstract class

4. an abstract class can have fields and constants defined

Interface

1. it just contains declarations. No implementation for any method.

2. we can not apply access modifiers to methods inside an interface

3. a class can inherit more than one interface

4. interface does not contain any field definition.

47. Can an interface is implemented by any number of classes?

a ) Yes.

48. What are the types of polymorphism?

a ) 2 types

1. operation polymorphism

2. inclusion polymorphism

49. How we achieve operation polymorphism and inclusion polymorphism?

a ) Operation polymorphism is achieved using overloaded methods and operators

And inclusion polymorphism is achieved using virtual functions.

50. what do you mean by compile time polymorphism?
a ) It is a process of selecting and binding the appropriate method to the object for a particular call at compile time.

22 August, 2009

C# Interview Questions - Part 4

Interview Questions
---------------------------
31. What are the inheritance types?
a ) 1. single level inheritance
2. multi level inheritance
3. multiple inheritance
4. hierarchical inheritance

32. Can we inherit the private members of a class
a ) Yes. But they are not accessible.

33. Why we use the keyword virtual?
a ) When you want to override a method of base class in derived class you should use this virtual keyword to the method in base class

34. Why we use override keyword?
a ) When you want to override a method of base class in derived class you should use this override keyword to the method in derived class

35. What are the abstract classes?
a ) Abstract classes are the classes for which we can not create objects. Means an abstract class can not be instantiated.

36. What are abstract methods?
a ) Abstract methods are the methods which does not contain their body part means they does not provide any implementation.

37. What are the properties of abstract methods?
a ) 1. they do not contain body part.
2. their definition/implementation should be given in non-abstract classes by overriding that method.
3. we can not use static modifier to it.

38. What are the sealed classes?
a ) If you want to prevent a class from being inherited you can use this keyword sealed to that particular class

39. What are sealed methods?
a ) A sealed method is a method which can not be overridden by its derived class.

40. Does a sealed class is an abstract class? Why?
a ) No a sealed class is not an abstract class. Because we can’t inherit a sealed class but we can inherit an abstract class.

21 August, 2009

C# Interview Questions - Part 3

Interview Questions
--------------------------

21. What are the properties of constant members?
a ) 1. They should use the modifier ‘ const’
2. Their value should be given when they are defined (it can’t be changed later)
3. They are implicitly static.

22. Why we use this keyword?
a ) This is used to distinguish local and instant variables that have the same name.

23. Does a copy of a static variable is created every time a class is instantiated?
a ) No.

24. What is a partial class?
a ) A partial class is a class which resides in multiple files. It should use 'partial' keyword. Generally it is used in situations where multiple developers need acess to the same class.

25. What is the name of the class from which all .net classes are derived?
a ) System.Object

26. Does c# support global variables?
a ) No. all declarations must be done inside a class.

27. Differences between property and indexer?
a ) Property
A property can be static member
The get accessor of a property corresponds to a method with no parameters
Indexer
An indexer is always an instant member
The get accessor of an indexer corresponds to the same formal parameter list as the indexer.

28. Differences between overloading and overriding?
a ) Overloading
1. used we want a method with more than one definition with in the same scope
2. in overloading, methods will have same name but different number, types, order of arguments.
Overriding
1. this is used when we have parent, child classes.
2. in overriding , methods will have same name with same arguments and same return type.

29. what is the order of the constructor execution in inheritance?
a ) They are executed from top(parent class) to bottom(child class)

30. what is the order of the destructors execution in inheritance?
a ) They are executed from bottom(child class) to top(parent/base class)

20 August, 2009

C# Interview Questions - Part 2

Interview Questions
---------------------------

11. Can we use access modifier on static constructor?
a ) No

12. How many static constructors we can declare for a single class?
a ) A class can have only one static constructor.

13. What is method overloading?
a ) It is a process of creating methods that have the same name but with different parameter lists and different definitions. This method overloading is used when you want your methods to do same tasks but using different input parameters.

14. What happens when we use ‘private’ modifier to a constructor of a class?
a ) When we declare a constructor of a class as private then we can’t create a objects of that class and we can not use that class as a base class for inheritance

15. Can we overload constructors?
a ) Yes

16. What are instant variables?
a ) Class variables are known as instant variables. Instant variables are different for each object and they are accessed using the objects. When ever a class is instantiated a new copy of the each of the instant variable is created.

17. What are static variables?
a ) These are also known as class variables. Static variables are common for all objects of a class. Only one copy of static variables will be created for all the objects of a class.

18. What are the differences between structure and class
a ) Structure:
It is value type
It is stored on stack
Does not support inheritance
Suitable for small data structure
Class:
It is reference type
It is stored on heap
Supports inheritance
Suitable for complex data structures

19. What is a value type? Give examples
a ) It stores value directly. Value types are stored on stack. Separate memory will be given for each instant of a value type.
Ex: int, float, char, struct

20. What are reference type?
a ) It stores a reference to the value. They are stored on heap.
Ex: class, string, array.

19 August, 2009

C# Interview Questions - Part 1

Interview Questions
------------------------

1. What are the main properties of object oriented programming?
a ) There are mainly 3 properties
1. Encapsulation/Abstraction
2. Inheritance
3. Polymorphism

2. What is encapsulation?
a ) This gives a way to hide the internal details of an object from its users.

3. What is inheritance ?
a ) It provides a way to build/create new classes using existing classes.

4. What is polymorphism?
a ) It provides a way to take more than one form.

5. What is a constructor?
a ) Constructor enables an object to initialize itself when it is first created.

6. What are the properties of a constructor?
a ) They are
1. They should have the same name as that of a class
2. They do not specify a return type.
3. we can use access modifiers to constructor.

7. How many types of access modifiers are there ?
a ) 5 types
1. Private
2. Public
3. Protected
4. Internal
5. Protected Internal

8. What access modifiers we can use for a class?
a ) We can use 2 access modifiers
1. Public
2. Internal

9. What is the default access modifier of a class?
a ) It is Internal

10. What is the default access modifier for class members?
a ) It is Private

18 August, 2009

Directives for Asp.Net Web Pages

Directives are used to specify the settings used by the page or usercontrol compilers to process pages or usercontrol files
There are 11 types of directives1.@Page: This is used to define page specific attributes. It is used only in .aspx files2.@Control: This is used to define Control specific attributes. It is used only in .ascx files3.@Master: This is used to define masterpage specific attribute. It is used only in .master files4.@Import: This is used to import a namespace in to the current page or usercontrol5mailto:5.@Register: This is used to render usercontrols and custom server controls in to a current page or usercontrolmailto:6.@Assembly:: This is used to link a page or usercontrol in to current page or usercontrol8mailto:8.@Implements: This is used to implement a specific .Net framework Interface in to current page or usercontrol9mailto:9.@Outputcache: This is used to apply cache techniques in to the current page or usercontrol10.@MasterType: This defines a class or virtual path used to type the master property of a page11.@Previouspagetype: This is used to create a strongly typed reference to the source page from the target of a cross page posting.

17 August, 2009

Differences between Asp and Asp.net

ASP----------
1. Asp supports interpreted model2. In asp you must place all directives on the first line of a page with in the same delimiting block3. Asp uses only 2 scripting languages vb script and java script4. Asp has no inbuilt facility for Validation of controls. Developer has to write code for both client side and server side validation
ASP.NET------------
1. Asp.net supports compiled model2. In asp.net you can place directives at any place in .aspx file . But standard practice is to place them at the begining of the file3. Asp.net is not constrained to 2 languages. we can use any .net complaint languages like c# vb.net etc4. Asp.net inbuilt facility for validation of controls. There are a set of validation controls which are easy to implement.

Goals of Asp.Net 2.0

The Goals of ASP.NET 2.0---------------------------They are1. Developer productivity2. Administration and management3. Performance and scalabilityDeveloper productivity: Much of the focus of the asp.net 2.0 is on productivity. It achieved it by introducing new controls like Gridview, detailsview, masterpages, sitenavigation and etc.Administration and management: Asp.net 2.0 now includes a Microsoft Management Console(MMC) snap-in that enables web application administrators to edit configuration settings easily.This allows system administrators to edit the contents of the machine.config and web.config files directly from the dialog instead of having them examine the contents of an xml file.In addition to this dialog, web or system administrators have a web based way called web administration tool to administer their asp.net 2.0 applications.Performance and scalability: One of the most exciting performance enhancements of asp.net 2.0 is its Caching capability. It includes a feature called SQL Cache invalidation.Before asp.net 2.0 it was possible to cache the results from sql server and to update the cache based on a time interval- for ex. every 10 sec so on. This means that the end user might see stale data if the result set changed sometime during 10 sec period. but by using asp.net2.0 new feature sql cahe invalidation the output cache is triggred to change when the result set from sql server changes.In addition to this asp.net 2.0 now provides 64 bit support.This means that now you can run your asp.net applications on a 64 bit Intel or AMD processors.

05 August, 2009

Flash Player Source Code

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
// GENERAL VIDEO PLAYER
/////////////////////////////////////////////////////
// Version 2.0
// Stephen Weber
///////////////////////////////////////////////////////
//
//TO RUN THIS WITH THE INCLUDED EXTRA EFFECTS YOU NEED TO HAVE MC_TWEEN2 LIBRARY
//GET THIS LIBRARY AT: http://hosted.zeh.com.br/mctween/
//INSTALL THE EXTENSION AND WHEN YOU PUBLISH IT WILL BE AUTOMATICALLY INCLUDED
#include "mc_tween2.as"
/////////////////////////////////////////////////////
// USER CONFIGURABLE VARIABLES
/////////////////////////////////////////////////////
//VIDEO TO BE PLAYED PATH
//Type the directory of the video to be played
var videoDirectory:String = "";
//Type the filename of the video file that you want to be played
var videoFileName:String = "video01.flv";
//
//Width of the Progress Bar
var barWidth:Number = new Number(progressBar._width);
//Set This Variable To True If You Want The Video To Trace
//Its Current Time and Total Time Consistently
var traceTime:Boolean = false;
//
//Set This Variable To However Many Miliseconds You Want The Video Controls
//FastForward and Rewind To Skip By
var skipTime:Number = 4;
//
//Set The Initial Volume of Video
//Note: Set this volume as a percentage
var initialVolumeLevel:Number = 50;
////////////////////////////////////////
// CUSTOMIZATION
////////////////////////////////////////
//SET THESE VARIABLES TO TURN ON AND OFF CERTAIN FUNCTIONALITY
//SET THESE TO TRUE TO TURN ON FUNCTIONALITY
//SET THESE TO FALSE TO TURN OFF FUNCTIONALITY
//
//VIDEO SCRUBER TO FASTFORWARD AND REWIND
var gotScrubber:Boolean = true;
//
//TO BE ABLE TO SEEK BY CLICK ON THE BAR TO SEEK TO THAT AREA
var barSeek:Boolean = true;
//
//SHOW MUTE BUTTON
var gotMuteButton:Boolean = true;
//
//SHOW VOLUME SLIDER BAR AND SCRUBBER
var gotVolumeSliderBar:Boolean = true;
//
//SHOW FASTFORWARD BUTTON
var gotFastForwardButton:Boolean = true;
//
//SHOW REWIND BUTTON
var gotRewindButton:Boolean = true;
//
////////////////////////////////////////
// FUNCTIONS
////////////////////////////////////////
//Loads Whatever FLV Video File You Send It
function playVideo(videoFile) {
stream_ns.play(videoDirectory + videoFile);
playMC._visible = false;
pauseMC._visible = true;
}
////////////////////////////////////////
// VIDEO ACTIONS
////////////////////////////////////////
//
////////////////////////////////////////
// VARIABLES
////////////////////////////////////////
progressBar._xscale = 0;
bufferBar._xscale = 0;
//Define Connection
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
//Progressive download.
var stream_ns:NetStream = new NetStream(connection_nc);
//Preloader
preloaderBar();
//Attach NetStream To Video Holder
my_video.attachVideo(stream_ns);
//This prevents the movie from playing right away, while it still preloads
stream_ns.seek(2);
stream_ns.pause();
////////////////////////////////////////
// Seek Functionality
////////////////////////////////////////
if (barSeek) {
bufferBar.onPress = function() {
//trace(bufferBar._xmouse);
var ratio = total_time / barWidth;
seekTime = ratio * bufferBar._xmouse;
stream_ns.seek(seekTime);
};
}
////////////////////////////////////////
// Audio Controller
////////////////////////////////////////
this.createEmptyMovieClip("flv_mc",this.getNextHighestDepth());
flv_mc.attachAudio(stream_ns);
var audio_sound:Sound = new Sound(flv_mc);
function progBar() {
progressBar._xscale = (stream_ns.time / total_time) * 100;
//If Movie reaches 98%, stop Fast Forwarding.
if (progressBar._xscale > 98) {
clearInterval(timer);
stream_ns.time = total_time;
}
if (traceTime) {
trace("Current time = " + stream_ns.time + " Total time = " + total_time);
} else {
}
}
stream_ns.onStatus = function(infoObject:Object) {
if (infoObject.code == "NetStream.Play.Stop") {
clearInterval(prog);
clearInterval(timer);
progressBar._xscale = 100;
rewindMC.enabled = false;
forwardMC.enabled = false;
videoBumper_mc.gotoAndPlay(2);
stream_ns.seek(0);
stream_ns.pause();
playMC._visible = true;
pauseMC._visible = false;
playMC.alphaTo(100,1);
}
};
startVideo2();
stream_ns.onMetaData = function(obj) {
total_time = obj.duration;
timer = setInterval(progBar, 20);
};
////////////////////////////////////////
// Preloader
////////////////////////////////////////
function preloaderBar() {
loaded_interval = setInterval(checkBytesLoaded, 10, stream_ns);
function checkBytesLoaded(stream_ns:NetStream) {
pctLoaded = stream_ns.bytesLoaded / stream_ns.bytesTotal * 100;
//trace(pctLoaded);
if (pctLoaded <= 100) { bufferBar._xscale = pctLoaded; trace(pctLoaded); } if (pctLoaded >= 100) {
clearInterval(loaded_interval);
progressBar_mc._visible = false;
}
}
}
////////////////////////////////////////
// Video Controls
////////////////////////////////////////
playMC._visible = true;
pauseMC._visible = false;
initial = 1;
playMC.onRelease = function() {
rewindMC.enabled = true;
forwardMC.enabled = true;
videoBumper_mc.gotoAndStop(1);
stream_ns.pause();
playMC._visible = false;
pauseMC._visible = true;
pauseMC.alphaTo(100,1);
playMC.alphaTo(0,1);
};
pauseMC.onRelease = function() {
playMC._visible = true;
stream_ns.pause();
pauseMC._visible = false;
playMC.alphaTo(100,1);
};

////////////////////////////////////////
// Rewind Controls
////////////////////////////////////////
if (gotRewindButton) {
var startingTime = stream_ns.time;
rewindMC.onPress = function() {
vidControl = function () {
stream_ns.seek(startingTime - skipTime);
startingTime = startingTime - skipTime;
};
timer = setInterval(vidControl, 200);
};
rewindMC.onRelease = rewindMC.onDragOut = function () {
clearInterval(timer);
};
} else {
rewindMC._visible = false;
}
////////////////////////////////////////
// Fastforward Controls
////////////////////////////////////////
if (gotFastForwardButton) {
forwardMC.onPress = function() {
vidControl = function () {
stream_ns.seek(stream_ns.time + skipTime);
};
timer = setInterval(vidControl, 200);
};
forwardMC.onRelease = forwardMC.onDragOut = forwardMC.onReleaseOutside = function () {
clearInterval(timer);
};
} else {
forwardMC._visible = false;
}
////////////////////////////////////////
// Volume Scrubber
////////////////////////////////////////
//CHECKS TO SEE IF VOLUME SLIDE BAR SHOULD BE ON
if (gotVolumeSliderBar) {

var volumeSlideBarWidth:Number = volumeSliderBar._width;
var volumeSliderStart:Number = volumeSliderBar._x;
var volumeSliderStop:Number = volumeSliderStart + volumeSlideBarWidth;

//Sets the initial volume
audio_sound.setVolume(initialVolumeLevel);
//Sets the initial volume scrubber position
volumeSlider._x = ((initialVolumeLevel/100)*volumeSliderBar._width)+volumeSliderStart;

volumeSlider.onPress = function() {
//Dragging Functionality
volumeSlider.startDrag(false,volumeSliderStart,this._y,volumeSliderStop,this._y);

//Setting Volume Based On X Position Relative To Volume Slider Bar
volumeSlider.onEnterFrame = function() {
ratio = 0;
ratio = Math.round(((volumeSlider._x / volumeSliderBar._width) * 100));
audio_sound.setVolume((ratio - 239)-initialVolumeLevel);
trace("VOLUME SET TO: " + ((ratio - 239)-initialVolumeLevel));
};
};
volumeSlider.onRelease = function() {
stopDrag();
};
volumeSlider.onReleaseOutside = function() {
stopDrag();
};
} else {
//TURN OFF VOLUME SLIDER BAR
volumeSliderBar._visible = false;
volumeSlider._visible = false;
}
////////////////////////////////////////
// Mute Controls
////////////////////////////////////////
if (gotMuteButton) {
muteMC.onRelease = function() {
//If Muted Or Not
if (muteMC._currentFrame == 1) {
//MUTE SOUND
muteMC.gotoAndStop(2);
audio_sound.setVolume(0);
} else {
//UNMUTE SOUND
muteMC.gotoAndStop(1);
audio_sound.setVolume(100);
}
};
} else {
muteMC._visible = false;
}
/////////////////////////////////////////////////////
// INITIAL RUN
/////////////////////////////////////////////////////
stop();
playVideo(videoFileName);