can't get movieClip from loaded swf - actionscript-3

With following code I import an external swf file. When I try to reach a movieClip that is named as temaResim in imported swf, Flash gives me error ,cant find the movieclip. I am pretty sure that I have temaResim in imported swf file, any help will be very useful.
Thanks guys.
function temaYukle(temaNo)
{
var resim:URLRequest = new URLRequest(yolum+"videolar/bilisselbecerilermodulu/17/"+temaNo+".swf");
var img:Loader = new Loader();
img.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
img.load(resim);
function imageLoaded(e:Event):void
{
setRegPoint(img,img.width/2,img.height/2);
if (temaNo==temam)
{
trace(e.target);
tema = e.currentTarget.content as MovieClip;
img.scaleX *= 0.85;
img.scaleY *= 0.85;
img.x = stage.stageWidth / 2;
img.y = stage.stageHeight / 2 - 20;
addChildAt(img,0);
// here comes error
trace(tema.temaResim);
temaMaske();
}
}
}
I worked on imported swf file When i import onther image to library of imported swf and set it's instance name as temaResim it works but When I try the image that ı have to, it dosn't work.

use Bracket syntax:
function temaYukle(temaNo)
{
var resim:URLRequest = new URLRequest(yolum+"videolar/bilisselbecerilermodulu/17/"+temaNo+".swf");
var img:Loader = new Loader();
img.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
img.load(resim);
function imageLoaded(e:Event):void
{
setRegPoint(img,img.width/2,img.height/2);
if (temaNo==temam)
{
trace(e.target);
tema = e.currentTarget.content as MovieClip;
img.scaleX *= 0.85;
img.scaleY *= 0.85;
img.x = stage.stageWidth / 2;
img.y = stage.stageHeight / 2 - 20;
addChildAt(img,0);
// here comes error
trace(img.content["temaResim"]);
temaMaske();
}
}
}
I hope this helps.

İt is unbelievable but true, I have to change the ımage That has name temaResim, Now it works,

Not the LoaderInfo holds the content ;-)
tema = e.currentTarget.loader.content as MovieClip;

Related

The movieclip contains various examples of names

How do I loaded MovieClips in the position of the mouse with a different name on each click? or I have to make several different MovieClips to laod?
please help me :)
Is this what you're trying to do?
var counter:int = 0;
stage.addEventListener(MouseEvent.CLICK, click);
function click(event:MouseEvent):void
{
var mc:MovieClip = new MovieClip(); // Or new YourExportedLibraryClip();
mc.name = 'mc_' + (counter++);
mc.x = stage.mouseX;
mc.y = stage.mouseY;
stage.addChild(mc);
}

AS3 | Load image from URL and start drag issue

I try to add image from URL address and start drag it when i click it, but i can't make drag function.
var url:String = 'http://www.helpexamples.com/flash/images/image1.jpg';
var urlRequest:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
loader.load(urlRequest);
addChild(loader);
function loader_complete(evt:Event):void {
var target_mc:Loader = evt.currentTarget.loader as Loader;
target_mc.x = (stage.stageWidth - target_mc.width) / 2;
target_mc.y = (stage.stageHeight - target_mc.height) / 2;
target_mc.addEventListener(MouseEvent.CLICK, startDraging);
}
function startDraging(e:MouseEvent):void {
var obj:MovieClip = e.target as MovieClip;
obj.startDrag();
}
The issue here is that in your complete function loader_complete() you set target_mc to a type Loader. Loaders do not have access startDrag() or stopDrag().
What you can do is create a new MovieClip and add your loaded content to that MovieClip. So in your loader_complete():
function loader_complete(evt:Event):void {
var target_mc:MovieClip = new MovieClip(); //new movieclip
target_mc.addChild( evt.target.content ); //add the content
target_mc.x = (stage.stageWidth - target_mc.width) / 2;
target_mc.y = (stage.stageHeight - target_mc.height) / 2;
target_mc.addEventListener(MouseEvent.CLICK, startDraging);
addChild( target_mc ); //add target_mc
}
Now your start drag should work.

ActionScript 3.0 - How to bring the current target into the movie clip?

How to bring the current target into the movie clip?
If we can set the current target into "selectMovieClip" variable then i believe we should be able to rotate or manipulate it as a MovieClip.
Please copy the script below and you will see what I mean. Currently I can't rotate it.
Please tell me what is wrong with my script. Thank you.
import flash.display.MovieClip;
/*create multiple MovieClip*/
for(var i:int = 0; i < 10; i++){
var widthSquare:int = 100;
var heightSquare:int = 100;
var square:MovieClip = new MovieClip();
square.graphics.lineStyle(1,0x0000CC);
square.graphics.beginFill(0xCCCCCC);
square.graphics.drawRect(0,0,widthSquare,heightSquare);
square.graphics.endFill();
square.name = "RotableClip_"+i;
square.x = 100 + (widthSquare*i);
square.y = 400;
addChild(square);
}
//SET MOVIECLIP
var selectMovieClip;//declare veriable
function onMousePress(evt:MouseEvent):void{
if( evt.target.name.indexOf("RotableClip_")==0){//only allow RotableClip_ to rotate
selectMovieClip=evt;
trace("Selected movie clip" + evt.target.name);
}
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMousePress);
//Rotate MovieClip
function MouseMove(evt:Event):void{
rotateTarget();//recreate the menu
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, MouseMove);
function onMouseRelease(evt:MouseEvent):void {
rotateTarget()
}
//rotateTarget OR at onMousePress
//How do we bring the movie clip into the below and rotate it.
function rotateTarget(){
selectMovieClip.rotation += 90;
trace("Rotate the movie clip");
}
In onMousePress() , you've assigned selectMovieClip to evt, not to evt.target ! Since selectMovieClip is not typed , Flash won't throw an error. Also,if you'd trace selectMovieClip as opposed to tracing evt.target.name, you would have picked up the error!

Controlling as2 swf playback in as3

I am embedding a swf built in flash 8 into an as3 project. When I call stop() or gotoAndStop(0); on the MovieClip that represents an instance of the embedded swf it stops for a sec and then continues. Trying to call removeChild on the mc removes it from the display but the audio in the swf keeps playing. The swf, in this case must be embedded, I cannot use loader. Any ideas
The code:
[Embed (source = "t1.swf")]
private var t1:Class;
private var mc:MovieClip;
public function iphoneTest()
{
var tf:TextField = new TextField();
tf.x = 10;
tf.y = 100;
tf.width = 100;
tf.height = 50;
tf.text = "Hello worl";
mc = new t1();
var button:CustomSimpleButton = new CustomSimpleButton();
button.width = 50;
button.height = 50;
button.x = 10;
button.y = 150;
button.addEventListener(MouseEvent.CLICK, onClick);
this.addChild(mc);
this.addChild(tf);
this.addChild(button);
}
private function onClick(e:MouseEvent):void {
mc.stop();
this.removeChild(mc);
}
did you try mc = null;?
also since you know it's an as2 swf, should probably use avm1movie instead of MovieClip
At very worst you can just kill all sounds in the SWF...
Make sure you import the sound mixer class then kill the sound..
import flash.media.SoundMixer;
SoundMixer.stopAll();
If your SWF has any hierarchy, you'll need to recurse through it to stop all movie clips.
private function stopAll(do:DisplayObject):void
{
var clip:MovieClip = do as MovieClip;
if (clip != null)
clip.stop();
var container:DisplayObjectContainer = do as DisplayObjectContainer;
if (container != null)
{
for (var i:int = 0; i < container.numChildren; ++i)
{
stopAll(container.getChildAt(i));
}
}
}

Flash preloader: Not preloading properly?

The preloader does not show up after 3% like it should have, it shows up when the file has loaded entirely.
Can someone help explain to me what I am doing wrong? My code is in the first frame, and it makes use of a rectangle object, and a textfield object. In other preloaders I have seen with code like this, it uses a movieclip with 100 frames. Does that make the difference? I have code updating the width of the rectangle, and something to update the text in the dynamic textbox as well.
My entire code in the first frame:
import flash.display.MovieClip;
import flash.events.ProgressEvent;
function update(e:ProgressEvent):void {
//trace(e.bytesLoaded);
if (loader) {
loader.text = Math.round(e.bytesLoaded*100/e.bytesTotal).toString() + " %";
}
if (bar) {
bar.width = Math.round(e.bytesLoaded*100/e.bytesTotal)*2;
}
}
loaderInfo.addEventListener(ProgressEvent.PROGRESS, update);
var loader:TextField = new TextField();
var bar:preloader_bar = new preloader_bar();
addEventListener(Event.ENTER_FRAME, checkFrame);
var loaderTextFormat:TextFormat = new TextFormat("_sans", 16, 0x000000, true);
loaderTextFormat.align = TextFormatAlign.CENTER;
loader.defaultTextFormat = loaderTextFormat;
bar.color = 0x000000;
addChild(bar);
addChild(loader);
// Extra test for IE
var percent:Number = Math.floor( (this.loaderInfo.bytesLoaded*100)/this.loaderInfo.bytesTotal );
if (percent == 100) {
nextFrame();
}
stop();
if (loader) {
loader.x = (stage.stageWidth - loader.width) / 2;
loader.y = stage.stageHeight / 2;
}
if (bar) {
bar.x = (stage.stageWidth - 200) / 2;
bar.y = (stage.stageHeight - bar.height) / 2;
}
function checkFrame(e:Event):void {
if (currentFrame == totalFrames) {
removeEventListener(Event.ENTER_FRAME, checkFrame);
startup();
}
}
function startup():void {
// hide loader
stop();
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, update);
var mainClass:Class = Main as Class;
addChild(new mainClass() as DisplayObject);
}
It really should be showing up, is there some fancy export option I need to change? I tried this with the bandwidth profiler, it only shows anything after the 100% mark.
EDIT: progress_bar is a movieclip which was exported for actionscript.
You problem seem very similar to this.
Short version: Do you have a single frame ?
If so, move as much as you can on the 2nd frame and also
set that as the Export Frame for actionscript.
Once your first frame has a small size, you will see the preloader easily.
HTH,
George