Jump to content


PanelScrollExample with swf's.

Recommended Posts

Hi there, i've gotten PanelScrollExample to work with swf's (rather than images), the only caveat being that the swf's must be output as AS2 swf's. 


When i instead try with AS3 swf's, i get the following message:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::MovieClip@33c47041 to flash.display.Bitmap. at com.greensock.loading::ImageLoader/_initHandler()
What does this error mean?   Why does it work with AS2 swf's but not AS3 swf's?   Is there anyway to make this work with AS3 swf's instead?
I'm trying publish into a mobile app using Air, but that process will not retain any of the AS2 coding, so i'm back to square one.
Link to comment
Share on other sites

Are you using an ImageLoader to load a swf?

Please make sure you are using a SWFLoader.


It's hard to troubleshoot flash errors without seeing any code. It's best if you attach the fla and code (zipped)

Link to comment
Share on other sites

Yes, ultimately, i think this was intended as an image loader, but i noticed i could get it to work with AS2 swf, as well.

This is the one i'm trying to use:
It simuates swiping, like on a phone.


It invokes an external ActionScript file, which directs to an XML that in turn points to a directory full of jpegs (or in this case, standalone swf's).


I would use an swf loader if i could find one that did the same thing.

* Very simple demo of panel flick-scrolling. It loads in an XML file
* containing the file names for 5 panel jpg files and then arranges them 
* side-by-side in a Sprite (_container) and makes it scrollable horizontally.
* Feel free to add more panels in the XML, change the _panelBounds position/size, 
* add a preloader, error handling, etc. the goal was to keep this simple. 
* Get more code at http://www.greensock.com
package {
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.*;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.utils.getTimer;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import com.greensock.TweenLite;
	import com.greensock.easing.Strong;
	public class PanelScrollExample extends Sprite {
		private var _panelBounds:Rectangle = new Rectangle(0, 0, 800, 480);
		private var _container:Sprite;
		private var _currentPanelIndex:int = 0;
		private var _panelCount:int;
		private var _x1:Number;
		private var _x2:Number;
		private var _t1:uint;
		private var _t2:uint;

		public function PanelScrollExample() {
			_container = new Sprite();
			_container.x = _panelBounds.x;
			_container.y = _panelBounds.y;
			addChildAt(_container, 0);
			_container.addEventListener(MouseEvent.MOUSE_DOWN, _mouseDownHandler, false, 0, true);
			var xmlLoader:XMLLoader = new XMLLoader("assets/panels.xml", {onComplete:_xmlCompleteHandler});
		private function _xmlCompleteHandler(event:LoaderEvent):void {
			var panels:XMLList = event.target.content.panel;
			_panelCount = panels.length();
			var queue:LoaderMax = new LoaderMax();
			for (var i:int = 0; i < _panelCount; i++) {
				queue.append( new ImageLoader("assets/" + panels[i].@file, {x:i * _panelBounds.width, width:_panelBounds.width, height:_panelBounds.height, container:_container}) );
			//feel free to add a PROGRESS event listener to the LoaderMax instance to show a loading progress bar. 
		private function _mouseDownHandler(event:MouseEvent):void {
			_x1 = _x2 = this.mouseX;
			_t1 = _t2 = getTimer();
			_container.startDrag(false, new Rectangle(_panelBounds.x - 9999, _panelBounds.y, 9999999, 0));
			this.stage.addEventListener(MouseEvent.MOUSE_UP, _mouseUpHandler, false, 0, true);
			this.addEventListener(Event.ENTER_FRAME, _enterFrameHandler, false, 0, true);
		private function _enterFrameHandler(event:Event):void {
			_x2 = _x1;
			_t2 = _t1;
			_x1 = this.mouseX;
			_t1 = getTimer();
		private function _mouseUpHandler(event:MouseEvent):void {
			this.removeEventListener(Event.ENTER_FRAME, _enterFrameHandler);
			this.stage.removeEventListener(MouseEvent.MOUSE_UP, _mouseUpHandler);
			var elapsedTime:Number = (getTimer() - _t2) / 1000;
			var xVelocity:Number = (this.mouseX - _x2) / elapsedTime;
			//we make sure that the velocity is at least 20 pixels per second in either direction in order to advance. Otherwise, look at the position of the _container and if it's more than halfway into the next/previous panel, tween there.
			if (_currentPanelIndex > 0 && (xVelocity > 20 || _container.x > (_currentPanelIndex - 0.5) * -_panelBounds.width + _panelBounds.x)) {
			} else if (_currentPanelIndex < _panelCount - 1 && (xVelocity < -20 || _container.x < (_currentPanelIndex + 0.5) * -_panelBounds.width + _panelBounds.x)) {
			TweenLite.to(_container, 0.7, {x:_currentPanelIndex * -_panelBounds.width + _panelBounds.x, ease:Strong.easeOut});


Link to comment
Share on other sites

I think you missed what I was saying about SWFLoader, its an actual tool that is part of the our LoaderMax tools. It is made specifically for loading swfs: http://api.greensock.com/as/com/greensock/loading/SWFLoader.html


in your code you are using an ImageLoader


queue.append( new ImageLoader("assets/" + panels.@file, {x:i * _panelBounds.width, width:_panelBounds.width, height:_panelBounds.height, container:_container}) );


try using


queue.append( new SWFLoader("assets/" + panels.@file, {x:i * _panelBounds.width, width:_panelBounds.width, height:_panelBounds.height, container:_container}) );

Link to comment
Share on other sites

Thank you much, and for clarifying for my misunderstanding. I will give this a go.

Link to comment
Share on other sites

It works perfectly now.  Thank you so much... Clearly, i have a lot to educate myself about Loaders and AS3, though i know the tool is functioning as i need to.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...



First things first: thank you all for reading this. This is my first post, so don't be so rough, pls.

I'm at the begining in flash and I've just found what I've been looking for my entire life, a way to make my pages swipe, just like on an iPad.

I'm using the same ThrowPropsPlugin, tonybot3 mentioned it a little earlier.

The only problem is that I've tried to make it responsive at some commands and I failed.

You know, this plugin has 5 scrolling demo pages.

Well, I've deleted those JPG's and inserted my own SWF's (AS2), after I modified the XML document, like this.


<?xml version="1.0" encoding="utf-8"?>
    <panel file="panel1.swf" />
    <panel file="panel2.swf" />
    <panel file="panel3.swf" />
    <panel file="panel4.swf" />
    <panel file="panel5.swf" />


I really don't know if it's enough or if I have to change the content of other files as well, but from my first expectations it worked really well.


Oh, my little problem is that I placed 5 buttons on the main frame.

I didn't find the right code that can be applied on the button itself, when you press it, to show the corresponding page, directly (without using the cursor).

If someone of you have the answer, would you want to tell it to me?

I know it may not be a serious "problem" for some people around here, but for a newcomer it's a real headache.

Thank you again.

Link to comment
Share on other sites

Hi marcus, 


I don't think I understand what you need help with, nor would I know what code is needed in your example. Perhaps you are referring to needing to add touch events? If so, maybe this will help:



We have to keep our support really focused on the GreenSock code and it sounds like you might need more general AS3 help, in which case I'd recommend the Adobe forums.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.