SyntaxScrewer's Blog

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!!
Advertisements

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.

May 9, 2011

Hello Molehill !! :D :D

Filed under: MoleHill — geekymaira @ 10:43 am

Hey Folks,

I’ve been waiting desperately to get my hands on the new Molehill API. Adobe made a public release with their flash player 11 incubator build.
I’ve been trying to keep up with the news and get my hands dirty. This post is just a summary of what all I’ve found out and tried so far 🙂

First things first!

What is Molehill ?

“Molehill” is the code name for a new set of low-level, GPU-accelerated 3D APIs that will enable advanced 3D experiences across screens through the Adobe® Flash® Platform runtimes. These new low-level APIs will provide advanced 3D and 3D engine developers the flexibility to leverage GPU hardware acceleration for significant performance gains. Today, Adobe Flash Player 10.1, renders thousands of non z-buffered triangles at approximately 30 Hz. With the new 3D APIs, developers can expect hundreds of thousands of z-buffered triangles to be rendered at HD resolution in full screen at around 60 Hz. Using the new 3D APIs in Flash Player and AIR will make it possible to deliver sophisticated 3D experiences across almost every computer and device connected to the Internet.

The 3D capabilities enabled by the new APIs will also be available to the broader developer community through popular ActionScript® 3D frameworks, such as Alternativa3D, Away3d, CopperCube, Flare3D, Minko, Sophie3D or Yogurt3D

How Can You Use Molehill ?

You need the following:

1) Flash Player 11 Incubator Build – This is a beta release by Adobe of the new Flash Player which has support for the Molehill API calls.

2) A 3D Framework/Engine/API – Well, you dont really need this if you can do really low level coding (Check out the link to Understanding Molehill below). But, in case you’d like to create a demo soon, I highly recommend using a 3D framework, like Away3D, Alternativa3D etc.

3) A 3D Artist – Yeah!!! You’d need 3D models to load up and have fun! If you’re like me and don’t know 3D modelling, you’d probably have to find a friend who can help you.

4) An IDE (Integrated Development Environment) – I use FDT, but you could try the free FlashDevelop OR IntelliJ (looks promising! I think its free!). John Lindquist has some really nice discussions about IDE to use for Actionscript3 development. He’s got video tutorials for IntelliJ too 🙂

5) Enthusiasm! 🙂

Setup Everything To Start Using Molehill.
I started out by trying to use AlternativaPlatform. They released v8.5 of their API which has wrappers for Molehill.

Note: The links below would help you to setup Molehill (Flash Player Incubator) with your IDE (FDT4.3 for me). The 2nd link will help you setup Alternativa8 too.
In case you decide to use another 3D engine like Away3D or Sophie3D, their installation support / documentation would probably be the best place to get help to get setup.

To set Alternativa8 & Molehill up in FDT4.3, I followed instructions on the links below and then I could get their examples to compile!

http://www.swfgeek.net/2011/03/07/targeting-flash-player-11incubator-build-in-fdt-4-2/
http://alternativaplatform.com/en/support/setup/
http://www.allforthecode.co.uk/aftc/forum/user/modules/forum (Away3D – Setting Up BroomStick examples.)

Since I haven’t used Alternativa earlier, I wasn’t too familiar with their API. So I started hunting for more news on
Molehill and got to know that Away3D’s come up with an API wrapper for Molehill too. It’s called “BroomStick”
The examples look brilliant!!

I am in the process of downloading the API right now and hopefully I can play around with it to get a demo up and running too!

My resources on Molehill are scattered as of now.
But here are a few that I thought were really helpful.

The Flash Player
http://labs.adobe.com/downloads/flashplatformruntimes_incubator.html
Adobe Labs Molehill Page
http://labs.adobe.com/technologies/flashplatformruntimes/incubator/features/molehill.html
Setup Flash Player 11 Incubator and FDT4
http://www.swfgeek.net/2011/03/07/targeting-flash-player-11incubator-build-in-fdt-4-2/
Alternativa Blog
http://blog.alternativaplatform.com/en/
Alternativa 8 Setup
http://alternativaplatform.com/en/support/setup/
Understanding Molehill – Digging Deeper Into Molehill
http://www.bytearray.org/?p=2555
Understanding Molehill – Alternativa 3D 8 Migration (Talks about a few underlying concepts of the flash player).
http://wiki.alternativaplatform.com/Alternativa3D_8_Migration
Away3D – BroomStick
http://away3d.com/away3d-4-0-alpha-release-broomstick
Away3D – Setting Up BroomStick examples.
http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=5&subindex=1&aid=263
MoleHill Demos
https://spreadsheets.google.com/pub?hl=en&hl=en&key=0Ak_lDHGdXjohdFRBOFVZUUdvRmRKVi1UdkdJUWJUM0E&output=html

Gotta get back to work!!

Cheers!
SyntaxScrewer.

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…)

« Previous PageNext Page »

Blog at WordPress.com.