Sunday, December 29, 2013

How to create horizontal gallery using Action Script 3.0 and Arrays?

Did you ever came across the gallery which it should repeat horizontaly whenever you would get to the last
element of the gallery, but the animation of that gallery had cut-offs that made watching that gallery quite
irritating even painfull and it wasn't happening continuously? The goal of the gallery I'm about to show you
should solve that problem.

Whenever I'd come across anything simliar and searched over internet, all the soultions I came upon were
strictly using Timeline which can bring several problems.Firstly, as everything that is being done with Timeline is controlling frames so the animation it self can have limitations. In this case, as animation is horizontal, whenever you click on the arrow "left" or "right" animation will in that moment stop everything that was doing and start from the frame that was given command to continue the animation from. And this is the reason why most of the horizontal galleries have those cut-offs which makes the animation somehow un-natural and at the same time not so "comfortable" to watch.

As it is example with this one:
Gallery Using TimeLine

It is not my goal to put bad voice on the creator of this gallery, my goal is to demonstrate the diffrence
between animation controlled by Timeline and the animation controlled by ActionScript classes and Arrays. If for some reason, user would want to watch 15th picture of gallery and to get to it faster, clicking on the button also faster would look very ugly. Would you have nervs to watch trough that if there was 50 of pictures?

Here it is how the gallery looks like when its being done using ActionScript classes and arrays.
Gallery Using ActionScript classes and Arrays


As you can see, if we are to click first and second picture in the bottom panel with pictures on the Main Stage several times in a row, we can notice that animation stops and continues at the point where user ordered to do so. If we are to click on the arrows "left" and "right" animation will happen continuously and every picture can be seen while the animation is "flying" from one picture to another.

I should mention that the classes for animations are taken on the page - http://www.greensock.com/ - where they eased the process of animating the objects a lot, rather then we would use the original Action Script 3.0
classes. Also the web-page supports classes for JavaScript so the principle of creating this gallery can also be applied for JavaScript.

To make this post shorter and you not bored to death of reading, I will write only few key points for gallery
for one button. The whole code and the gallery you can take here:
Flash file with end results 

Firstly we created an array as this:

var myArray:Array = new Array();

Then that Array we have filled with elements that are being placed on the MainStage and their type is MovieClip,

their InstanceNames are mc1, mc2, mc3. Which means one picture is mc1 second one mc2 and so on.

myArray[0] = mc1;
myArray[1] = mc2;
myArray[2] = mc3;

We also have added one variable in order to control the position of element in the array:

var i:Number = 0;

So for now we have an array that has three elements. Now we will add an Event for the button so that the

pictures can move when the user clicks on that button. And we have done so as this:

btn.addEventListener(MouseEvent.CLICK, go);

Now our button has an Event that will be engaged on the Click of the Mouse and execute the function called "go".

Function "go" does next:


function go (evt:MouseEvent):void
{
 
   TweenMax.to(myArray[i], speed, {x:-1280});
   TweenMax.to(myArray[i], speed, {blurFilter:{blurX:70, blurY:0, quality:2}, ease:Cubic.easeOut});

if(i == 0)
{
thmb3.alpha = .4;
thmb2.alpha = .4;
thmb1.alpha = 1;

}
else if( i == 1)
{
thmb3.alpha = 1;
thmb2.alpha = .4;
thmb1.alpha = .4;
}
else
{
thmb3.alpha = .4;
thmb2.alpha = 1;
thmb1.alpha = .4;
}

i++;


if(i == myArray.length)
{
i = 0;

//Tweening current object in array to the center of screen starting from the 1280px and blur
TweenMax.to(myArray[i],0,{blurFilter:{blurX:70,blurY:0, quality:2}});
TweenMax.to(myArray[i], speed, {x:0,startAt:{x:1280}, ease:Cubic.easeOut});
TweenMax.to(myArray[i], speed, {blurFilter:{blurX:0,blurY:0, quality:1}});
}
else
{
//Tweening any other element of the Array while i is being incremented
TweenMax.to(myArray[i],0, {blurFilter:{blurX:70,blurY:0, quality:2}});
TweenMax.to(myArray[i], speed, {x:0,startAt:{x:1280},ease:Cubic.easeOut});
TweenMax.to(myArray[i], speed, {blurFilter:{blurX:0,blurY:0, quality:2}});
}
}



So we have several things. As we can see TweenMax is one of the classes that are made from GreenSock and I would strongly suggest you to check out on their web-page how the animation is being executed. In short, because every line of code which contains "TweenMax" and inside of it "myArray[i]" written, it means that animation will be executed with the element which variable i states it is currently on. Variable i is at the same time incrementing by one which is written in button code as "i++;" and the if/else statements check two things. In first if/else statment it cheks the value of variable i, and based on that, it sets the alpha for the pictures in the bottom panel with the pictures that are being named as thumb1, thumb2 and thumb3. In second if/else statement it cheks if the value of variable i is larger then the posible ammount of elements in array, and if it is so the value of variable will be set to zero which means the begining of an array, and if it is not it will continue incrementing of the variable i.

Now we have a button which, whenever user clicks, it checks certain conditions and executes animation using TweenMax classes.

That would be at the same time the main principle of the whole gallery! Everything else has been done by the
same principle. For every picture, events has been added which use same classes and elements. Diffrence is that button "left" and "right" have diffrent X cordinates for animation (from left to right and vica-versa) and the pictures in the bottom panel on the main screen engage animation based on which picture have been choosen.

I hope this will be of use to readers of this post if for nothing else then for discovering new things such are TweenMax classes and if not for Flash and ActionScript then for JavaScript.

Monday, December 23, 2013

Adobe Flash - Dying breed or...

It's been a while since I have used Flash for web/app development and that got me to think when did I last time find a page on the internet that was Flash based? And...I barely remember any at all.

The first question that comes to my mind was why is this happening? I personaly always liked Flash for its
vector graphics and also the way animation can be done inside of it. I mean latest versions have Inverse
Kinematic (IK) wich means u could probably create a good cartoon in there with all the characters or you could just create a cartoon character that could interact with user as he absorbs the content of the page. And thats kinda the good and bad side of it.

Good side, in my opinion is, because in some cases if you do something wild as creating character toon for
interction with users, users can recognize that character as some indication for the info they are absoring. But
also Flash gives an oportunity to build rich and very attractive content. If you think using Flash for this
reason or any reason that bring more usefull content to your users I think you should go for it.

Another good side from my point of view is that, once you created a web-page or application in Flash, wherever and whoever opens that page it will always look the same! In short, it has no issues with cross-browser compatibility so you would never have to worry if a browsers might present your page/app diffrently as it is the case with HTML and CSS web-pages.

Also another good aspect for using Flash is if you wish to develop a video game. I've seen and played a lot of nice games when I had "one of those awesome classes" on my university and I never really payed attention was it Flash or not. What I am trying to say is that users if they search for web-games most of them are in Flash.

In short Flash is powerfull tool if you wish to create, games, vector graphics, animations sound effects etc.
But what if user who wants to see your page gets a messege saying "you must install plug-in to view this page" and what he does is "...not this again...*clicks X button in top-right corner*"? Not everyone will want to upgrade or install Flash player to see the application you have to show, tho I am not sure how much is that the case today as most of the things being played on the internet goes through Flash player. But that's not the only down-side of it.



If you do a full web-page in Flash, generaly is not good because of SEO or Search Engine Optimization and that is probably the biggest problem of it all. Because it can't get any link that otherwise it would if it is done
in HTML, therefor whenever user search for something that your Flash web-page have , it won't be "seen" by any search engines (Google, Bing, Yahoo! etc.). My advice would be to whenever you need to do a web-page and you want a Flash inside of it, try doing it so that Flash section doesn't have some significant impact on the page. Such would be dynamic loading of the video files, but then you would have to use additional coding. Or some side menu for latest posts of something.

Most of the Mobile phones can't read flash. Enough said. Today people are using phones probably every 10min for something and if they cross the page that is full-based Flash and it can't open it? Well you don't need to be rocket scientist to know what will happen then! And this is for users who have such phones to view web-pages on it.

So after mentioning few good and bad sides of Flash, question still remains "should we use it or just forget
about it?" There are some alternatives to Flash I never checked but I've read somewhere that Adobe released a tool for converting Flash to HTML5 and that Google have done the same. I wonder tho how does that effect on links...

So, should we use it? Should we leave it rott? Or there are, or there will be alternative solutions that will
make Flash convert to HTML with ease. I guess time will tell.

Monday, December 16, 2013

Have you ever got a Job Preview then escape the first day of the work?


I had an easy or seminar I had to write about Human Resource Management for the university and what caught my attention was the paragraph that was written in a book Management by Stephen P Robbins & Mary Coulter. The paragraph was about, giving to a candidate for a job, a Realistic Job Preview. Reason why this caught my attention was because I know a person who was in exactly the same situation and then she doubted herself if it was her problem or fault that she couldn't stand being in an environment like the one she was.

Reason that led her to leave that job because the Job Preview she had was completely different than when she came to the first day of work. In a book it is said that if organization tells an applicant only the good aspects, they're likely to have a workforce that is dissatisfied and prone to high turnover. And a lot of negative things can happen when an applicant gets an excessively inflated.

Firstly, mismatched applicant probably won't withdraw from the selection process. Second, inflated information builds unrealistic expectations so new employees may quickly become dissatisfied and leave the organization. And Third, new hires become disillusioned and less committed to the organization when they face the unexpected harsh realities of the job that no one told them about. Not to mention that these individuals may feel that they were misled during hiring process and then become a problem employee.

Which is exactly the three things that was being done to the persone I speak of. Like they had a manual opposite of Management book where they followed to do exactly those three things. And it is because they never gave her a Realistic Job Preview, which includes both positive and negative information about the job and the company.



For instance, in addition to the positive comments that are usualy being said during an interview, the job applicant might be told that there are limited opportunities to talk to coworkers during work hours, that promotional advancement is unlikely or that work hours are erratic and they may have to work weekends. In fact, the book states the researches which indicate that applicants who revcieved Realistic Job Preview have more realistic expectations about the jobs they'll be performing and therefore are better able to cope with the frustrating elements then those who recieved only inflated information.

Either way, what makes more sense to you?