Feed

Pure as3 Lightbox clone

by Felipe Lima 29/03/2010 19:04

There are a plenty of lightbox implementations around the web. Whenever you need one, you won't need to make up your own for sure. Just pick one of the available options. However, if you're restricted to flash only, the options get reduced drastically. This is why I came up with my own lightbox implementation with ActionScript. You can see it in action in my company's website.

Flash Lightbox screenshot

It works just like the regular lightbox versions:

var:Lightbox myLb = new Lightbox(
    _sTitle: String,    // lightbox title
    _sLinkToVisit: String = null,     // link to the page that will be visited upon click
    _sImageText: String = "Imagem", // 'Image' text   
    _sOfText: String = "de");        // 'Of' text    

// shows the lighbox with the provided array of images
myLb.show(['image1.jpg', 'image2.jpg', ...]);

myLb.hide(); // closes the lightbox

Please be aware that, in order to use it, you'll have to create a Lightbox movieclip in the Flash IDE with the following elements inside it:

_txtClientName, _txtCurrPos, _btnNext, _btnPrev _btnClose, _bg and _btnAcesse.

These elements are referenced inside the Lightbox class, so you'll need to create elements that match these names in the IDE so that the class will find them.

Additionally, you'll need two static variables containing the stage original width and height. This is needed in order to automatically reposition the lightbox in the middle of the screen on stage resize.

Also, you'll need to download TweenLite for the all the effects to work!

Please let me know if you have any suggestions of bug fixes and/or improvements and I will be happy to answer your requests.

If I summed it all up, I must have spent more than a day struggling to disable request validation with asp.net mvc. It is just ridiculously hard to disable it. 

It turns out that the only way to disable it once and for all is a combination of a setting in the web.config and the ValidateRequestAttribute. 

 

  1. Add the following line to your web.config file right after <system.web>: <httpRuntime requestValidationMode="2.0" />
  2. Add the [ValidateInput(false)] attribute to the controller and the action method you want to expose
  3. Rebuild the project and go drink a beer.

 

Remember it may be unsafe to disable request validation due to potential vulnerability XSS and XSRF attacks.

Note: This is targeted to ASP.NET 4, when the requestValidationMode attribute was introduced. In .NET 3.5, you can skip the first step and only do 2 and 3, but I'm not 100% positive about that.

Happy coding :) 

During the last couple days I've been experimenting with MongoDB and its C# driver, cleverly written by Sam Corder. I'm investigating it as a replacement for a SQL Server database I am using in a web application that is higly community driven. This specific characteristic is the one that makes the NoSQL movement rise atop regular RDBMS systems like SQL Server or MySQL, since it is hard to mantain relational integrity in these scenarios. Other key features of MongoDB are focus on performance and scalability.

K. Scott Allen already wrote a quick intro on using the C# driver, so I used it as a tutorial for my first steps. Here are some thoughts I'd like to share on this topic:

  • I don't like being held by the verbosity of instantiating Document objects every time I want to manipulate the database, so I've written method overloads for the main operations, like Insert, Update, Find and Delete that receive a plain object and only then convert them to Document. This allows us to leverage anonymous objects in C# and makes the code cleaner:
   1:  Mongo mongo = new Mongo();
   2:  mongo.Connect();
   3:  Database db = mongo["testdb"];
   4:  var col = db["users"];
   5:   
   6:  foreach(Document d in col.Find(new { name = "John Doe"}).Documents)
   7:  {
   8:      int johnId = d["_id"];
   9:      int johnName = d["name"];
  10:  }

  The code with this implementation is available on my fork of the driver at github an will hopefully be merged with the master soon.

  • MongoDB allows storage of files in the database, as well, through the GridFS specification. The C# api is already implemented and functional. Follow an example for writing a file to the database:
   1:  void Main()
   2:  {
   3:      Mongo mongo = new Mongo();
   4:      mongo.Connect();
   5:      Database db = mongo["test"];
   6:      var collection = db["testcollection"];
   7:      GridFile file = new GridFile(db);
   8:      
   9:      using(GridFileStream fs = file.Create("mycv")) // define the file name
  10:      {
  11:          ReadWriteStream(File.OpenRead(@"C:\Data\felipelima_en.doc"), fs);
  12:      }
  13:  }
  14:   
  15:  public static void ReadWriteStream(
  16:      Stream readStream, 
  17:      Stream writeStream)
  18:  {
  19:      Byte[] buffer = new Byte[Int16.MaxValue];
  20:      int bytesRead = readStream.Read(buffer, 0, Int16.MaxValue);
  21:      // write the required bytes
  22:      while (bytesRead > 0)
  23:      {
  24:          writeStream.Write(buffer, 0, bytesRead);
  25:          bytesRead = readStream.Read(buffer, 0, Int16.MaxValue);
  26:      }
  27:      readStream.Close();
  28:      writeStream.Close();
  29:  }

Database files work just like plain Documents and will be assigned an Id upon creation. Therefore, they can be later queried just like a regular document.

This was just a quick glance over MongoDB and C# integration. I'm planning on using it on a large project and will post here my findings. More to come.

Tags: , , ,

About the Author

myself
My name is Felipe Lima and I am a Software Engineer and co-founder at Quavio, a digital agency at Porto Alegre, Brazil. I am interested in technology, programming with the .Net Framework and sports. Check out my full profile.

Powered by BlogEngine.NET 1.4.5.0