Old 03-07-2007, 11:33   #1 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
Join Date: May 2005
Location: St Helens
Posts: 460
actionscript 3

now that you cant use actionscript on buttons, or loadmovie, flash is really wrecking my head.

ive managed to get some on over events to work using:
Code:
menuBtn01.addEventListener(MouseEvent.MOUSE_OVER,menu_select01); function menu_select01(MouseEvent):void { this.gotoAndStop("option01"); }

but i cant figure how to get a movie to load from the library into a holder.
i keep coming across load(Loader) but have no idea how to use it.

can anyone help?
  Reply With Quote
Old 04-07-2007, 10:55   #2 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
Join Date: May 2005
Location: St Helens
Posts: 460
ok forget the first post.

ive got a version working, but not exactly how i need it to.
this is my code.
Code:
menuBtn01.addEventListener(MouseEvent.CLICK, fadeselection01); function fadeselection01(MouseEvent):void { trace("click"); var request:URLRequest = new URLRequest("test_import.swf"); var loader:Loader = new Loader() loader.load(request); parent.parent.holder.addChild(loader); }

this method loads an external swf file:
Code:
var request:URLRequest = new URLRequest("test_import.swf");

what i cant figure out is how to load a movieclip from the library.
i have set the linkage options to export the movieclip for actionscript and given it a name "Image02" but cant get it to link.

any ideas on this guys?
  Reply With Quote
Old 04-07-2007, 11:24   #3 (permalink)
proc355
Trailer Trash™
 
proc355's Avatar
 
Join Date: Sep 2006
Posts: 852
do the usual linkage/export for actionscript malarkey, giving it a "Class" value, e.g. "Example", in the linkage dialog then do something like:

Code:
var e:Example = new Example(); addChild(e);

cant find that monkey in the docs like, must be well buried or i'm blind...

hth

*obviously your scope for the addChild() can be specified, e.g. container.addChild(e)
  Reply With Quote
Old 04-07-2007, 11:35   #4 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
Join Date: May 2005
Location: St Helens
Posts: 460
i got it.

var Image2:MovieClip = new Image();
addChild(Image2);

Image2 is the instance name once its on the stage.
Image is the linkage name.

why cant they make it clear bloody coders!

Last edited by dpc036 : 04-07-2007 at 12:17.
  Reply With Quote
Old 04-07-2007, 13:44   #5 (permalink)
proc355
Trailer Trash™
 
proc355's Avatar
 
Join Date: Sep 2006
Posts: 852
dont want to piss on your parade but technically that's incorrect

the compiler won't catch it since your Image class is inheriting from MovieClip; also, not sure how you're getting the instance name you infer above, it doesn't work for me - you have to specify the properties before adding the child (or when calling the constructor if you implement that i suppose, havent tried it)

so:

Code:
var i:Image = new Image(); i.name = "bungholio" addChild(i);

to be honest i thought the new compiler would be stricter in type checking... i wouldn't count on that behaviour
  Reply With Quote
Old 04-07-2007, 14:54   #6 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
Join Date: May 2005
Location: St Helens
Posts: 460
but your code doesnt work.
mine does!
  Reply With Quote
Old 04-07-2007, 16:27   #7 (permalink)
proc355
Trailer Trash™
 
proc355's Avatar
 
Join Date: Sep 2006
Posts: 852
Image2 is a reference var (which you are incorrectly typing as MovieClip) to your newly created object of class Image - not it's instance name.

Check your Debug > List Objects



Grab the FLA

Last edited by proc355 : 04-07-2007 at 16:43.
  Reply With Quote
Old 05-07-2007, 04:08   #8 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
Join Date: May 2005
Location: St Helens
Posts: 460
I appreciate you taking the time to help.
and i can see that your code does work.

but so does mine, see attached.
Attached Files
File Type: zip test.fla.zip (77.1 KB, 3 views)
  Reply With Quote
Old 05-07-2007, 05:46   #9 (permalink)
proc355
Trailer Trash™
 
proc355's Avatar
 
Join Date: Sep 2006
Posts: 852
lol ok - it's easy to come across as "i'm bloody right and you aint" so please believe me that isn't what i'm saying, ok?

last two things i'll say on this unless you need clarification

1) typing your var to MovieClip rather than Image negates the advantage of having strict typing - it works because your Image class inherits from MovieClip but it isn't correct; since everything inherits from the Object class you might as well just type all your variables/arguments to "Object" - you see where this is going? it's pointless. use it to your advantage.

i spend most of my time dealing with ruby these days, which isn't strictly typed - much better imo - but, and it's a strong but, in languages where the compiler depends upon strict typing for some of it's functionality it's better to play by the rules, lest headaches and tears ensue - there are some cases in which you will not get away with it.

you don't have to strictly type anything in flash, but in the advent of a bug you're giving the compiler less information to work with - you'll get less back in the way of information to fix it.

you're making life harder for yourself. don't do it! be lazy!

2) your instance name is not being set to "Image2" as you said, it's being set to "instance2" which is just a generated name - if you expect to be in control then you have to explicitly name things - you still havent looked at your debug output or you'd see it yourself:

Level #0: Frame=1
Movie Clip: Frame=1 Target="_level0.holder"
Shape:
Movie Clip: Frame=1 Target="_level0.holder.instance2"
Shape:

that's from your fla

apart from syntax none of this has changed from AS2.0 - there's only a change in that you can now instantiate MovieClips and their descendents using the "new" keyword which is the way it's done for anything else (and the way it should be) - no more attachMovieClip shite.

hth
  Reply With Quote
Old 05-07-2007, 10:29   #10 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
Join Date: May 2005
Location: St Helens
Posts: 460
you didnt come across like.
not being an actionscript pro your initital solution didnt really make sense to me. then i couldnt see why my version wasnt technically correct, but worked.

thanks again

Last edited by dpc036 : 05-07-2007 at 11:43.
  Reply With Quote
Old 05-07-2007, 12:31   #11 (permalink)
proc355
Trailer Trash™
 
proc355's Avatar
 
Join Date: Sep 2006
Posts: 852
cool - telling someone something is wrong although it works is always a bit dodgy like :P

bottom line is they've fixed it, and it's proper oop without the voodoo inherited from previous versions
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8