Archive for category ActionScript 2

This is not SPAM, VIAGRA.ca is live!

I have been working hard (that’s the last joke I make on this, I don’t event know if I am allowed) on this website for a long time, but it’s finally live!. Because of canadian regulation on advertising and pharmaceutical prescription drug, the process of making the canadian version of the VIAGRA website is unlike other; more steps are involved when you try to get content approved. So that’s why I have been working on this for a long time, but it’s finally out and I am really happy of the results.

What is funny when you work on a project for such a long time is the fact that you improve so much in the mean time, that you look back at your early code and you can’t believe you did that. During I was working on the VIAGRA website,  I switched animation package three time to end up with TweenLite, I started looking at SWFAddress now I kinda use it on every project, knew nothing about AS3 and so on. It was also the first project where I started using Object Oriented techniques to build it.

When I present a website I did, I like to list all the libraries I used, so here I go again. Well first it was all built in Actionscript 2.

Most of the 3D was done using 3D Studio Max exept for the button animations that where done using Maya.

Well that’s it, go and hang around the VIAGRA.ca clubhouse!

That conclude my week of posting everyday (well I didn’t post yesterday, but I posted twice today), see you in a month (just joking).

, , , , ,

2 Comments


Again on BlendMode (this time in AS2)

I was really happy when I found out how to do proper fade outs of MovieClips containing other MovieClips, but I am even more happy now because I found how to do it in ActionScript 2. I don’t know why but I was thinking that blendMode was something new that came in Flash 9, but I actually knew it came with Flash 8 at the same time that filters came in. I woke up when my colleague told me he and to roll back an animation from Flash 8 to Flash 7 and had to loose the blendModes because of that.

The way to do it is really similar than in ActionScript 3, it’s actually way easier but more prone to errors (if you mispell “layer” the compiler won’t tell you):

1
my_mc.blendMode = "layer";

That’s all there is to it.

, , ,

No Comments


ExternalInterface Problems in ActionScript 2

Where I work we use a lot of Javascript because the guys doing it are quite gifted and also because I am the only member of the flash department (well designers do flash, but when it gets complicated I handle it), so it is often the case where Flash has to call a Javascript function. With all of my readings I had come to the conclusion that ExternalInterface.call was the best way to access Javascript functions. I guess I was wrong…

Well first of all ExternalInterface works very badly with Opera (at least the ActionScript 2 version, haven’t tested the ActionScript 3 version). Searching a bit I found people saying the it worked sometimes, it worked when it wasn’t inside a mouse related event, etc. Well this isn’t very reliable.

Also I ran in some trouble where when the Javascript was called in the html it worked fine in all browsers, when I used ExternalInterface it worked fine in Internet Explorer, didn’t do a thing in Opera and just crashed Firefox. Well that’s nice cross-browser behavior…

To solve my problem, I just had to do it the good old way; getURL(“javascript:myFunction()”). For the same Javascript function (the one that crashed FireFox), it worked in all browser. I hope this all works better in AS3.

, ,

3 Comments


Using Delegate to have the right scope when using TweenLite, Tweener and Events in ActionScript 2

Not so long ago I was having a bad day using Flash 8 and ActionScript 2 just after completing a project in ActionScript 3. Now this Dan Hunter dude made a comment saying I should try using this Delegate class. Well last week I thought I should give it a try so I head over the blog post and try to figure out what it is used for. I had heard the word Delegate before, but never quite understood it.

So I look at the post and it is exactly what I hate in a post; it is very technical and not quite to the point. I don’t think I am a bad programmer and I should understand stuff like that but there is something missing in the post: why should I use this class in the first place?

Well I am going to tell you why you should used this class; because it will give you the right scope of the function called by the delegate function. Ok, ok maybe I’m not quite clear either, but go read this article on how to use the Delegate class and you should understand everything. I found it while installing the new version of Flash Develop (beta 6). The real useful thing about the Delegate class is that it permits you to use the “this” you want inside the function you want.

Here is my example using events; let’s start by using a simple button on click custom event. So you make this custom button class that handle the rollover and rollout internally and when you have a onrelease event, you send an event to the class containing the button. You do so in order to keep your code clean and well organized. Here is the code you would have for the event listener inside the class that will contain the custom button:

1
2
3
4
5
myCustomButton.addEventListener("click", handleClick);
 
function handleClick(evt:Object):Void{
  trace (this)//this will actually refer to myCustomButton instead of the containing class
}

By using the Delegate class, “this” will refer to the containing class. Here is how you do it:

1
2
3
4
5
myCustomButton.addEventListener("click", Delegate.create(this, handleClick));
 
function handleClick(evt:Object):Void{
  trace (this)//this will refer to the containing class
}

This will save you the trouble of having to find in which scope you are and also having to use this._parent all the time.

Another good use of the Delegate class is when you use the onComplete argument with Tweener or TweenLite. When you use the onComplete argument with both these Tweening engines, it will call the function you specify it when it will be done Tweening. With Tweener this function will be scoped to the MovieClip your doing a Tween on and with TweenLite the function will be scoped to the TweenLite Object which is not very convenient. Here is how you would use the Delegate class for these situation:

1
2
3
4
5
6
7
Tweener.addTween(myCustomButton, {_alpha:100, time:1, onComplete:Delegate.create(this, doNextStep)});
 
TweenLite.to(myCustomButton, 1, {_alpha:100, onComplete:Delegate.create(this, doNextStep)});
 
function doNextStep():Void{
  trace (this)//this will refer to the class containing the Tweening code
}

Well this will save me a lot of trouble. I was thinking that I was a good programmer and that experience didn’t really mean anything but these little things, like using the Delegate class to have the scope you want or know that TweenLite is faster than Tweener which is faster than the Adobe Tween classes,  can only be acquired with experience and they make your days a whole lot better. This kinda is a lesson of humility.

, ,

2 Comments


ActionScript 2 and Object Oriented Programming; an entire day of trouble

I was back to work today after the holidays and my first day hasn’t been that fun. First of all I’m back working in ActionScript 2 after working on the cool Christmas card which was in ActionScript 3. Second, I have been trying all day to make my menu work while programming it in an object oriented kinda way but all my efforts have been in vain.

 The first big problem I encountered is that even if you assign a class to a symbol in the library, if you put that symbol on the stage, it won’t use the class you assigned to it. You have to use the attachMovie method in order to make that work. Ok that’s fine I can find workaround in order to make that work.

Now I finally get that working the trouble is that the onRollOver and other onSomething won’t work in that class because of where it is situated (in an other class or other bug I just couldn’t find). Well I lost my whole day on that…

I feel it’s kinda wasteful to spend time on problems like this (in ActionScript 2) because I am not really learning something that will be useful in the long run. Anyway I don’t usually like to make post like this, because I don’t provide an answer to my problem but I really had to get this out of my system. Sorry about this, better post next time.

, ,

3 Comments


PrintJob problems in ActionScript 2

What I did mostly today was debug some ActionScript code on printing. All the basics about printing can be found in this tutorial. But as usual, what you want to do is more complicated than the basics. I have to talk a bit about my setup for you to understand the problem. What I usually do for a project, is that I load my content on 3 levels. The first level is the preloader which loads the shell (an external file) on level 2. The shell will load all the other content (also external files) on level 3. Also, because of all the rounded corners, content will be loaded under a mask.

So what I wanted to print was in the content MovieClip. I set out to do was in the tutorial, and everything worked really fine until I wanted to move the printArea MovieClip outside the visible screen (that’s the basic principle to do good printing using ActionScript). The big problem here is that content is under a mask so when I move the printArea out of the mask it become invisible so it won’t print. In order to solve that I had to attach the printArea MovieClip on the shell level (which is not under a mask). It sounds easy, but it took me 2 hours to find.

An other problem I had was that I was trying to offset a bit the stuff that I am printing so that when it prints there is a margin at the top and left. Well it seems that even if you offset (move a bit less and down) it doesn’t work, because for a reason, Flash start printing at the first pixel it encounters top and left. I think to circumvent that, I’ll put a single white pixel at 0, 0 so then my offset will work.

I hear there is also a problem with multiple page printing, but all my pages fit in one page so I did not have to solve that problem also

, ,

2 Comments