Copy link to clipboard
Copied
Hello all, I am trying to load a SWF in to an Application, then have that application create X amount of that original SWF. Back in the days of AS2, you call the duplicate function, but no more in AS3.
So, I have been able to do this by creating a new class then create a new object in a loop (works fine) there are 2 ways i've been able to do this:
Both of these create a unique version of the SWF (GREAT!) however, when i use the second method, the mouse and keyboard events don't work, (even though the added and OEF both work on both) and for the life of me i can't figure out why.
If i place a breakpoint at the end of the for loop i see that 'b' has 7 listeners. Anyone have this issue / provide suggestions for solutions?
Thanks!
-Andrew
package
{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.getClassByAlias;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
public class Test3 extends Sprite
{
public function Test3(){
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, handleLoadComplete );
loader.load( new URLRequest( "some/url/here" ) );
}
public function handleLoadComplete( _event:Event ):void{
var a:MovieClip = (_event.target as LoaderInfo).content as MovieClip;
var c:Class = _event.target.applicationDomain.getDefinition("linkageName");
var e:Class = Object( a ).constructor;//Class(a.getDefinitionByName(getQualifiedClassName(a)))
for(var i:int = 0; i < 1; i++){
var b:MovieClip = new c();
b.addEventListener( MouseEvent.CLICK, handleClick ); //if Class == c, fires, else nothing
b.addEventListener( MouseEvent.MOUSE_MOVE, handleClick ); //if Class == c, fires, else nothing
b.addEventListener( KeyboardEvent.KEY_DOWN, handleClick ); //if Class == c, fires, else nothing
b.x = Math.random() * 300;
b.y = Math.random() * 300;
b.addEventListener( Event.ADDED, handleAdded ); //fires
addChild( b );
b.addEventListener( Event.ENTER_FRAME, handleOEF ); //fires
b.addEventListener( MouseEvent.CLICK, handleClick ); //if Class == c, fires, else nothing
b.addEventListener( MouseEvent.MOUSE_MOVE, handleClick ); //if Class == c, fires, else nothing
}
}
private function handleClick( _event:Event ):void{
trace(" in the click" );
(_event.currentTarget as MovieClip).x +=20;
}
private function handleAdded( _event:Event ):void{
trace(" i am added" );
(_event.currentTarget as MovieClip).x +=20;
}
private function handleOEF( _event:Event ):void{
trace(" i've entered a frame" );
(_event.currentTarget as MovieClip).x +=20;
}
}
}
Copy link to clipboard
Copied
Interesting observation...
I played with it for awhile and it looks like objects instantiated through constructor and sometimes event classes gotten through applicationDomain.getDefinition loose their InteractiveObject flavor.
If this is intentional - it may make sense for security reasons (I am not sure about it though). Otherwise, let's what can be found on this topic...
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more