SyntaxScrewer's Blog

October 24, 2011

Linking fl.* package in FDT

Filed under: ActionScript 3.0,Flash — geekymaira @ 4:22 pm

Hello fellows,

This is a rather simple post. It shows two methods in which you can use the fl.* package in your NON Flash IDE.

Method 1:
http://troyworks.com/blog/2008/01/04/using-flcontrols-with-fdt-and-flash-cs3/

Method 2:
http://evolve.reintroducing.com/2007/10/30/tips-n-tricks/fl-package-swc/


Hope this works.

Thanks

SyntaxScrewer!

August 19, 2011

SWF in a SWF in a SWF SHELL = Exception fault: TypeError: Error #1034: Type Coercion failed:

Filed under: ActionScript 3.0,Flash — geekymaira @ 2:59 pm

Hello folks!!

I got stuck with this bugging bug!! and I just HAD to share it.
So, I had a Main SWF that loaded up a MapClass swf and a SHELL that loaded up the Main swf. Everything worked when I debugged the Main SWF alone. But as soon as I debugged the shell, I got the following error.

Exception fault: TypeError: Error #1034: Type Coercion failed: cannot convert a.b.c::MapEvent@c899eb1 to a.b.c.MapEvent.
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at com.iomedia.components::MapDocumentClass/onMapButtonClicked()
My Project structure was

<Root>
   <src>
	<a>
           <b>
             Main.as
             Shell.as
               <c>
                 MapDocumentClass.as
                 MapEvent.as
   <fla>
      <maps>
        MapClass.fla   //SRC path set as   "../../src"   DOCUMENT CLASS: a.b.c.MapDocumentClass

Basically, I had 3 levels of nesting of swf's.
SHELL SWF <- MAIN SWF <- SHELL SWF

When I compiled the Main.as file it automatically compiled the event class and had it ready for the Erroneous Swf to use. So everything was peachy!
However, when I compiled the SHELL SWF, it didn't compile the Event Class because there was no reference to it in the Shell.as class.

The solution :

1) Create  a dummy variable for the event in the Shell.as class
2) Import the Event Class so that it gets compiled.

Everything worked after that!!

May 25, 2011

(localToGlobal & globalToLocal) vs (SyntaxScrewer) – //INCOMPLETE

Filed under: ActionScript 3.0,Flash — geekymaira @ 8:37 am

– Complete this.

RobotLegs Mediator Behaving Funny With Multiple Instances of Mapped View – //INCOMPLETE

Filed under: ActionScript 3.0,Flash — geekymaira @ 8:35 am

– Complete this.

October 11, 2010

event.stageX vs mouseX – credits to mrmg from #irc – Horizontal Drag n Scroll Carousel related issue

Filed under: ActionScript 3.0,Flash — geekymaira @ 3:51 pm

[WARNING: The title of this post might not seem relevant, unless you read the whole thing]

Hey,

I’ve been working on a game where I needed a scrolling horizontal carousel (if you may).
I made a simple class to handle the scrolling based on the mouseX. It worked , but was
buggy. I tried but couldn’t figure out what was wrong. Hence, IRC 😀

Anyway, there were 2 issues. I’ll explain them with code and examples.

ISSUE 1: It seems like the solution to this issue, didn’t change much visually, but I like this way better.
Feels more logical. So I had my class setup like below.

package views 
{
	import utils.Constants;
	import com.greensock.TweenLite;
	import flash.events.MouseEvent;
	import com.greensock.easing.Quart;

	import flash.display.MovieClip;

	/**
	 * @author Sameer Maira
	 */
	public class CarouselBaseClass extends MovieClip 
	{
		private var scrolling : Boolean;
		private var lastX : Number;
		private var _carousel : MovieClip;
		private var _parent : MovieClip;
		private var carouselTween : TweenLite;
		private var newX : Number = 0;
		private var _spacing : Number;

		public function CarouselBaseClass()
		{
		}

		public function setupScrolling(target : MovieClip,spacing:Number)
		{
			_carousel = target;
			_spacing = spacing;
			
			_carousel.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			Constants.MAIN_STAGE.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			_carousel.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		}

		private function onMouseMove(event : MouseEvent) : void
		{
			if (scrolling)
			{		
				if (mouseX < lastX)
				{		
					if (newX > -1287)
					{
						newX = _carousel.x - _spacing;
					}
				}
				if (mouseX > lastX)
				{
					if (newX < 0)
					{
						newX = _carousel.x + _spacing;
					}
				}
				if (mouseX != lastX)
				{	
					carouselTween = TweenLite.to(_carousel, 1, {x:newX, ease:Quart.easeOut});
				}
			}
		}

		

		private function onMouseUp(event : MouseEvent) : void
		{
			scrolling = false;	
		}

		private function onMouseDown(event : MouseEvent) : void
		{
			lastX = mouseX;
			scrolling = true;
		}
	}
}

Now, the issue that was pointed out was with the way I had my event listeners setup for the MOUSE_UP, MOUSE_MOVE & MOUSE_DOWN events. Plus I was using the “scrolling”
boolean which wasn’t really needed when I fixed the event listeners. The solution(better implementation) was to :

1) add the MOUSE_UP & MOUSE_MOVE event listeners to the stage.
2) add the MOUSE_MOVE & MOUSE_UP event listeners when the MOUSE_DOWN was triggered.
3) remove the MOUSE_UP & MOUSE_MOVE when the MOUSE_UP was triggered.

The code then looked something like what’s given below :
PS: I realized a few other silly things I had done, which were corrected & commented in the code.

package views 
{
	import utils.Constants;

	import com.greensock.TweenLite;
	import com.greensock.easing.Quart;

	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	/**
	 * @author Sameer Maira
	 */
	public class CarouselBaseClass extends MovieClip 
	{
		private var scrolling : Boolean;
		private var lastX : Number;
		private var _carousel : MovieClip;
		private var _parent : MovieClip;
		private var carouselTween : TweenLite;
		private var newX : Number = 0;
		private var _spacing : Number;

		public function CarouselBaseClass()
		{
		}

		public function setupScrolling(target : MovieClip,spacing : Number)
		{
			_carousel = target;
			_spacing = spacing;	
			_carousel.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
		}

		private function onMouseMove(event : MouseEvent) : void
		{
			//Dont want it to scroll if the mousePos hasn't changed.
			//On the other hand. Why would this event handler be triggered if the mouse position hasn't changed
			//you idiot. Sheesh!
			
			//TODO: Get a brain.
			if (mouseX != lastX)
			{
				if (mouseX < lastX)
				{
					//TODO: Cannot hard code the bound limits - different for different derived class objects.
					//Pass them as params.
					if (newX > -1287)
					{
						newX = _carousel.x - _spacing;
					}
				}
				if (mouseX > lastX)
				{
					if (newX < 0)
					{
						newX = _carousel.x + _spacing;
					}
				}
				TweenLite.killTweensOf(_carousel);	
				carouselTween = TweenLite.to(_carousel, 1, {x:newX, ease:Quart.easeOut});
			}
		}

		private function onMouseUp(event : MouseEvent) : void
		{
			//scrolling = false;	
			Constants.MAIN_STAGE.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
			Constants.MAIN_STAGE.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
		}

		private function onMouseDown(event : MouseEvent) : void
		{
			lastX = mouseX;
			//scrolling = true;
			Constants.MAIN_STAGE.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
			Constants.MAIN_STAGE.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
		}

	}
}

ISSUE 2: So, the reason for this post is this issue. Basically my scrolling was buggy. You can see why if you look
at the example below.

[EXAMPLE]

The scrolling seems a bit jittery doesn’t it ? Yes it does. Try scrolling small amounts. It’s still jittery.
The various probable causes that we thought of (just to mention) were.

– The Children are catching the mouseEvents (The hikers & the numbers) : Verified to make sure mouseChildren = false;
– The Tweens were overlapping. ie. Before the 1st tween could complete, another tween would begin due to the dragging. : Killed all tweens for the object before starting a new tween.

None of the above were the issue.

Finally mrmg, suggested that I replace “mouseX” and use “event.stageX” instead. Well guess what!!! That worked.
I’m not sure why but from what I got to know from mrmg (by the way, that’s a person on IRC), was that it might be due to 2 issues.

– Local/Global coordinate problem
– The mouseX value might be getting cached on the last frame of the event handler, whereas event.stageX was not.

I’m not sure if I still understand, why it really solved the issue. I’m glad it did or else I’d be stuck for days.
If you know the reason, please comment. I really want to know.

Here’s how it looks after the correction.

[EXAMPLE FIXED]

Great little nugget of information.
All thanks to mrmg.

-SyntaxScrewer

Dynamically resizing the Stage.

Filed under: ActionScript 3.0,Flash — geekymaira @ 3:25 pm

Hey,

So I haven’t really tried this out yet, but someone on IRC shared a link. I saw the examples
on the website and it looked promising. Will play around later. Posting this just for reference
for the future.

[HOW TO DYNAMICALLY RESIZE THE STAGE]

-SyntaxScrewer

September 10, 2010

RobotLegs – Dispatching events from the view, making the mediator listen.

Filed under: ActionScript 3.0,Flash — geekymaira @ 7:57 pm

Hi,

So basically I was trying to do something really basic in RobotLegs and got stuck.
Wanted to dispatch an event from a view and listen to it in the mapped mediator.
The problem was that I was dispatching the event from the view before it actually got added
to the stage ie. Before the view dispatched the ADDED_TO_STAGE event.

The mediator wouldn’t catch any event because it was dispatched before the ADDED_TO_STAGE
for the view, which I think is when the onRegister() for the mediator gets executed.

Finally got it fixed. The solution was simple – Added a listener to the mediator for the ADDED_TO_STAGE event of the mediated view
and called a public function view.init(); from the handler. Dispatched the desired event from the view.init() function.

So the things to keep in mind are :
– Add mediators to views before adding the view to the context.
– Before dispatching an event from the view, make sure the view has dispatched the ADDED_TO_STAGE event.
– Listen to the ADDED_TO_STAGE event in the mediator and call an init() function on the view.

PS: This post was written essentially so that I don’t land in the same situation again 🙂

Cheers!
SyntaxScrewer.

September 9, 2010

Bullets & Nested Bullets in a dynamic html text field. //INCOMPLETE

Filed under: ActionScript 3.0,Flash — geekymaira @ 5:37 pm

– just a placeholder to remind me I gotta write about this – 😀

August 5, 2010

Making an interactive chain in AS3 (without any physics)

Filed under: Flash — geekymaira @ 8:44 am

Heylo folks,

Many-a-times it happens that one makes an ill informed hurried analysis of a simple problem. This is followed by rapid questions on IRC / discussion forums etc, until someone
someone more sensible comes along and makes you realize what a dumb ass you’ve been. 😛

Well something similar happened to me the other day. The task at hand was to create an interactive chain sortta an element for a  project. I started thinking about Physics / The Bone Tool
Linked Lists and what not. I knew I was thinking too much for a simple problem but I couldn’t strike the solution. Then finally, I logged onto IRC and asked around.

Here was my question ,

The answer was – YES!
However, that’s not the one I chose.  The stuff I couldn’t figure out was the “Links” between the nodes.
How would they rise / stretch when the node rises on rollover.  Do I rotate them? Do I scale them ? What should I do ???

The solution was elementary – Anchor the links to the nodes and redraw the links every frame.
That way when a node’s position changes, the new link is drawn from the previous node to  the new position, thus giving
a “stretching” effect when  you use a tween to update the  nodes position. (more…)

July 21, 2010

Firefox MouseWheel Problem with Flash Embedded Objects.

Filed under: Flash — geekymaira @ 10:19 am

Hey,

It’s been a while since I posted something new on the blog. I remember running into some problems a while back with custom flash scrollbars , the mouse wheel and firefox!

The problem was that my code worked great in flash player but started messing up when I tested it on Firefox after embedding the swf into an HTML. Internet Explorer didn’t have an issue with the scrolling (although I had to click the flash object once to activate it), but for Firefox it failed miserably. So I googled like crazy, found a few workarounds and after reading countless articles and a few code hacks, I discovered that it was a problem with firefox. In very simple words, firefox liked taking control of all the MouseWheel events that occurred on the page. So they never reached my flash object  like I wanted them too : ).  Moreover, I had 2 scrollbars on the stage and one MouseWheel event. So even when the MouseWheel event was passed to my flash object from the browser (if ever), it didn’t control the correct scrollbar. I’m not sure if only 1 worked or both did. It’s been a while.

Anyway, what was the solution ? (more…)

Next Page »

Create a free website or blog at WordPress.com.