| Ultrashock Forums
• App: MVC Gallery |
|||
![]() |
||||
| Search this Thread | Thread Tools | Display Modes |
| 123>>> | Page 1 of 6 |
|
|
|||||||||||||||||||||||||
![]() |
Ultrashock Member Comments:
|
2005-11-28
#2 |
||
|
Last edited by Codemonkey : 2007-03-01 at 14:58.
|
|
|
2005-11-28
#3 |
||
|
Last edited by Codemonkey : 2006-01-22 at 15:16.
Adding slideshow functionality: Ok, when I said that this is easy to do, I didn’t lie. All you need to do is add a button to the Controls asset, and when that button is hit, it sends a request to the model telling it to slideshow the images. The model then updates the active image at an interval and sends an update to all the views each time. Step by step: 1. Go to the GalleryModel class and add these two methods ActionScript Code:
ActionScript Code:
4. Open the class Controls, and add the public variable btn_slideshow:MovieClip. Now we can use the button inside the class. 5. Open up the class ControlsView and add this method ActionScript Code:
ActionScript Code:
ActionScript Code:
|
|
17 Creative Assets
|
2005-11-28
#4 |
||
|
Wheyhey! Very nice, Codemonkey. I haven't read through it all in detail yet (I'm pulling an all-nighter so I'll read it all later on) but it's all looking good. Let the battle of the Galleries begin. ![]() A quick question for you... As far as the MVC pattern goes, am I right in thinking that the Model only sends data to the View, and the Controller only sends data to the Model? |
|
|
2005-11-28
#5 |
||
|
Originally posted by Nutrox In my implementation yes. The model sends data to the view using an info object, and the controller pulls the strings in the model on requests by views. The only other way would be if the views used getter methods in the model instead of using the info object.Wheyhey! Very nice, Codemonkey. I haven't read through it all in detail yet (I'm pulling an all-nighter so I'll read it all later on) but it's all looking good. Let the battle of the Galleries begin. ![]() A quick question for you... As far as the MVC pattern goes, am I right in thinking that the Model only sends data to the View, and the Controller only sends data to the Model? Thanks
|
|
|
2005-11-28
#6 |
||
|
very nice. i shall have to play around with this one a little later.
|
|
|
2005-11-28
#7 |
||
|
Wonderful, Codemonkey. Very nice. ![]() Thank you! |
|
17 Creative Assets
|
2005-11-29
#8 |
||
|
Another question for the Codemonkey. ![]() Which class in the MVC pattern would handle the re-positioning of movie clips when the Stage was resized ( Stage.onResize ) ? I imagine it's the View class, but is it viable for something outside of the MVC pattern to deal with Stage resizes? |
|
|
2005-11-29
#9 |
||
|
Yeah, I put it in the GalleryView (since that class is responsible of creating the interface). I could've included it in the function setupStage in the Gallery class, that's is the jumpstart class for the application. But wherever it is, it has to be able to get through to the gallery view, to be able to call its realignmethods. Btw, did you hit the keyboard with your head yet?
|
|
|
2005-11-29
#10 |
||
|
Nice example monkey, I'm sure plenty of members will find it very helpful In regards to the stage resizing, would it not be the case that a controller would be responsible for reacting to a stage resize event and calling an appropriate function of a custom stage object in the model to set it's new state. Using your chosen implementation of the MVC pattern, Views can then register with this custom stage object and position themselves according to the info object (data transfer object) sent to them. |
|
|
2005-11-29
#11 |
||
|
If the stageresize had an impact on the actual data inside the model, I would say yes, the controller should update the model (or its stageobject) and then the model can update the views. But, since the stageresize is an aesthetic change only (not a change to match the model's data), the controller is allowed to update the view directly. As you said though, the controller should probably be watching the stage for resize events, not the view. |
|
17 Creative Assets
|
2005-11-29
#12 |
||
|
Originally posted by Codemonkey Hehe... nope, not yet. I've done that thing where you stare at the screen for about 10 minutes in a mind-numbed state though. ... Btw, did you hit the keyboard with your head yet?
![]() You've actually got me interested in this whole MVC thing so I'm trying to structure something similar at the moment, but I'm including a class that handles audio as well ( Model, Display, Controller, Audio ). The Audio class isn't part of the "chain" though really, it's just connected to the Model class ( Model >> Audio | Model << Audio ). I might also use a Global class that contains static pointers to the Model, Display, Controller, and Audio classes... and then simply import Global when one class needs to talk to another. I'll see how it goes though. |
|
|
2005-11-29
#13 |
||
|
Originally posted by Codemonkey I see where you're coming from. Let me give some reasoning behind what I said.If the stageresize had an impact on the actual data inside the model, I would say yes, the controller should update the model (or its stageobject) and then the model can update the views. But, since the stageresize is an aesthetic change only (not a change to match the model's data), the controller is allowed to update the view directly. As you said though, the controller should probably be watching the stage for resize events, not the view. I believe the controller should only directly update the view if there is no change to the related model's state (data), say reordering your images into alphabetical order for example. I would say the Stage itself should be represented in the model as it has a state (alignment..) and these can be changed. As such this should not be done directly by the controller. |
|
|
2005-11-29
#14 |
||
|
WOW. Nice. You guys are awesome. For me it is a HUGE HELP! Hats down to you!!!!!!! Imre |
|
|
2005-11-29
#15 |
||
|
Originally posted by BadSanta I see your point. Then the real question is: is the stage size 'state' part of the gallery data, or part of the interface that represents it?I would say the Stage itself should be represented in the model as it has a state (alignment..) and these can be changed. As such this should not be done directly by the controller. Why do you feel the stagesize part of the galleries intrinsic properties if not of the interface? |
|
|
2005-11-29
#16 |
||
|
Ah ok, I think I get what you're saying (when you say interface I always think code ).Well in this setup, your stage happens to only hold one view (GalleryView). Say the stage held 2 or more views at one time, then which one would have the stage size as their properties? Both, could be one answer but that's not very scalable. My current line of thought would be to have a singleton, say StageModel, that views can subscribe to (along with other views) through their controller. Oh that's another thing, it's perfectly valid for a view to subscribe to more than one model at a time. You would have to refactor your code slightly to allow this. I would also be tempted to put stage resize listener directly into this StageModel as the width and height properties are read only and could not be set through a controller anyway, only alignment etc. can... but that's probably not the most "correct" thing to do for reasons stated previously (a controller should handle input events, but in this case the event has already update the stage x/y props, so what else would the controller need to do to the StageModel? Hmm but then again perhaps you would want the controller to perform some other custom action after a stage resize.. yeh I take it back in the controller is better! ).
|
|
17 Creative Assets
|
2005-11-29
#17 |
||
|
I've decided to put the Stage.onResize related stuff into the Controller. The reason is that the user can click on a button to adjust the size of the GUI manually, and the Controller would need to catch that request and update the Model. It makes more sense to me to have the Stage.onResize event call the Controller in the same way the View does when the user manually resizes the GUI, because both events are the same as far as the Controller and Model is concerned, and both events have exactly the same result ( the Model and View are updated ). |
|
|
2005-11-29
#18 |
||
|
I wish one day I could understand how the hell you did that.
|
|
|
2005-11-29
#19 |
||
|
Originally posted by Nutrox Yes, then you labeled the Stageresize event as a view itself that updates the model via the controller, like any other view. BadSanta wants it to be part of the model, or a completely separate model.. and I still don't know what I want I've decided to put the Stage.onResize related stuff into the Controller. The reason is that the user can click on a button to adjust the size of the GUI manually, and the Controller would need to catch that request and update the Model. It makes more sense to me to have the Stage.onResize event call the Controller in the same way the View does when the user manually resizes the GUI, because both events are the same as far as the Controller and Model is concerned, and both events have exactly the same result ( the Model and View are updated ). ![]()
Originally posted by Chaosfact Don't worry, I was where you are not so long ago I wish one day I could understand how the hell you did that.
|
|
|
|
2005-11-29
#20 |
||
|
sorry to ask but .. how come the photogallery doesnt work in my comp it just give me alot of errors .. damn i feel dumb asking this
|
|
|
2005-11-30
#21 |
||
|
I don't know? ![]() Do you have AS2 turned on? |
|
|
|
2005-11-30
#22 |
||
|
thanks CD ![]() never mind it works now |
|
|
2006-01-03
#23 |
||
|
Wow Codemonkey... Most impressive. I cannot believe how many different AS files are here for this all to work. Is if even feasible to do (the final outcome; your demo) in one swf without having all the external AS files?
|
|
|
2006-01-03
#24 |
||
|
Well, the .as classfiles you probably are referring to are compiled into the swf. So when publishing, all you need is the swf and the images in the gallery (and the html file).
|
|
|
|
2006-01-03
#25 |
||
|
First of all, I don't want to start on a negative note: This is a great implementation. It is a very good example for learning MVC (which all of us can use) and is a great "tutorial" for learning how to extend classes and learn how interactions of classes may work. Outstanding work codemonkey! My concerns are two fold: 1. Why not make more properties for the view available through the fla? My point being, this is very easy to create a new class, make a slideshow, and point it to an image folder. But if you passed this off to a "designer" they would have very few options available to them, to resize the piece, give information about layout of thumbnails, location of main image, size, background color, ect? I would think extra properties for the fla would make sense, to make this Gallery singleton very easy to change on the fly. Then making it a tool that can be used by anyone inside of the fla - then it can intermingle with other elements you create in the fla. It could even become a listener to other things going on in the root fla. 2. It is called "slideshow" but I see no timing elements in it? I have created a "Timer" class, which could probably be added to this to trigger a new image after a set amount of time passed. If you want this class, email me at todd@haleypro.com. Otherwise, this rocks, can't wait to get deeper into it. |
|
|
2006-01-03
#26 |
||
I'll bite1. You're right, the gallery should be as dynamic as possible and controllable by any developer. Which is exactly how I tried to create it. The whole point of MVC is to have one central model with all properties and changeable data. The model hinges on the xml file. This means that whatever the developer wants to change it just has to update the xml file and make sure the model uses it and passes more data to the views in the Update Object. Now as you can imagine I kept the xml file and the model quite simple for sake of overview, but if you truly want to make it dynamic you'll want to add sections to the xml for every part of the gallery, like navigation parts with buttons size position where to get the images of the interface from etc., categories for the images and whatnot. 2. It's not called slideshow, but webgallary.... but, I did add a slideshow option to it (did you read the "adding slideshow functionality" post?). See the two small buttons between previous and next? Those are slideshow normal, and slideshow random, both are timed at 5 seconds. |
|
|
|
2006-01-03
#27 |
||
|
You're right, the gallery should be as dynamic as possible
It just seems like there needs to be more getter/setter methods or parameters for the singleton Gallery class to make those options available on the fla level, instead of a designer having to open actionscript code to create those permutations. That was my only point. I do think you have made this very changable and updatable, and it is very flexible.
It's not called slideshow, but webgallary
My bad, that serves me right for skimming the post.
|
|
|
2006-01-03
#28 |
||
|
Originally posted by tcoulson Ahh, I think I misunderstood you before. Ok see, the setup is actually meant to contain everything possible within the webgallary, making setters/getters obsolete altogether. The idea is to make it as robust as possible so that any user really only needs to customize the existing attributes in the xml, but not update the gallery code itself. In the example, yes you need to dig into the code to actually make it robust, but mind you this isn't a release version right.It just seems like there needs to be more getter/setter methods or parameters for the singleton Gallery class to make those options available on the fla level, instead of a designer having to open actionscript code to create those permutations. You could make it a setter/getter version on fla like you said, but doing that would make it some AS1-2 hybrid, which could be ok I guess. But then you would need to make the xml reading etc. also apart from the gallery itself, so you can call setters/getters according to the xml file. Is that what you meant? |
|
|
|
2006-01-04
#29 |
||
|
making setters/getters obsolete altogether
I just don't think that is a good idea. I think a lot of coders get so wrapped up in making everything encapulated into AS files and a single keyframe on the timeline that they lose sight of how having code on the main timeline is not a detriment in all cases. This is why Macromedia brought back the Normal mode - terrible move, but they did it so that the program would be more designer friendly.
In the example, yes you need to dig into the code to actually make it robust
That is why I think it is a problem. To a designer - they won't dig through the code to make it three columns of pictures instead of two - they just wont. They won't dig through code to change the background color of the gallery. [/quote]
but mind you this isn't a release version right
Here is where I agree with you. It isn't a release version, it is a learning OOP exercise, this is why I think what you have done is fantastic, it is going to reinforce a lot of what I have thought about in the past. And it is a great piece of work. I am just making suggestions to make it ready for prime time.
but doing that would make it some AS1-2 hybrid
AS1 is not the devil if it makes your code usable to more people.
make the xml reading etc. also apart from the gallery itself
I am not suggesting touching the xml. I think the handling of that is perfect. But in the same vain, I think you should set up some default values, like number of columns, colors, buttons, ect that the user can set right along with the xml path parameter - then make some getter setter methods that they can change those parameters on the fly if they choose. That's all. Preserve the xml handling though, I like the way you are doing that - just handle a few more options in the same way.
|
|
|
|
2006-01-04
#30 |
||
|
PS- If I get some extra time this week, maybe I will extend it and show you what I mean.
|
|
|
2006-01-04
#31 |
||
|
Originally posted by tcoulson That's just it, nobody needs to be digging in the code with a release version, that's the whole point of it. It's all in the xml file by then.That is why I think it is a problem. To a designer - they won't dig through the code to make it three columns of pictures instead of two - they just wont. They won't dig through code to change the background color of the gallery. I understand what you mean, and for designers it's probably convenient to be able to run changes on the fly using getters and setters, but I'm not just copulating code here. The class Gallery is the application not the webgallery. The application creates the webgallery and so to change anything using setters/getters you do that in the application using setters and getters that are on the singleton webgallery instance inside the application class, not in the main timeline. I guess its a matter of taste to treat the Gallery class with static run() as an application rather than the main timeline. |
|
|
|
2006-01-04
#32 |
||
|
yeah, we are in an argument of taste. I always make getter and setters so that my designers around the office don't need to understand my code. Or even look at it for that matter. I would rather they assign values to create the makeup of it and not have to know xml or flash actionscript to create it. But like i said in the start, it is a preference not an absolute.
|
|
17 Creative Assets
|
2006-01-04
#33 |
||
|
I will leave you two to continue to discuss this, the only input I have is: I think getters and setters are a good thing is most situations, especially when you want to allow someone to change property values from withing Flash ( without touching the actual class code or other external files ). Components are a classic example of where getters and setters can come in very handy, and most of the Macromedia classes use getters and setters in one way or another. Don't forget we are not talking about C++ here. Trying to follow all of the C++ (etc) rules when using ActionScript just seems odd, and in the world of Flash it can sometimes also be limiting. If we can create a class that extends the MovieClip class, and allow someone to change the appearance of the movie clip using getters/setters, then we shouldn't feel doing that is "bad" in any way. That's what Flash is all about, it's a kick ass dynamic/visual/code hybrid monster, and I love it for being that way.
|
|
|
2006-01-04
#34 |
||
|
Originally posted by Nutrox Agree entirely with this statement. It's a little like the code behind in C#. Separate the code from the view, but in this case we also allow the designer to set properties in the IDE during design. Very powerful, allowing the designer to focus on the design. If we can create a class that extends the MovieClip class, and allow someone to change the appearance of the movie clip using getters/setters, then we shouldn't feel doing that is "bad" in any way. That's what Flash is all about, it's a kick ass dynamic/visual/code hybrid monster, and I love it for being that way.
|
|
|
2006-01-04
#35 |
||
|
Originally posted by Nutrox Nicely put. Well, I guess I'm being a little bit of a tightass here... maybe If we can create a class that extends the MovieClip class, and allow someone to change the appearance of the movie clip using getters/setters, then we shouldn't feel doing that is "bad" in any way. That's what Flash is all about, it's a kick ass dynamic/visual/code hybrid monster, and I love it for being that way.
|
|
17 Creative Assets
|
2006-01-04
#36 |
||
|
Originally posted by Codemonkey No, not at all. The Codemonkey is not a tightass. Nicely put. Well, I guess I'm being a little bit of a tightass here... maybe
![]() I've been looking at C++ recently, preparing myself to learn it this year (gulp!), and I will definitely be walking the proper MVC route once I start putting code together. With Flash though, I just think that we have the luxury of approaching things from a slightly different angle while still keeping a lot of the visual mechanics separate from the data, and making life a little easier for those who aren't too code-savvy. |
|
|
|
2006-01-04
#37 |
||
|
as am I. Like we said, its a matter of choice and opinion. If it makes you feel any better - flex seems to be more encapsulated like your code was created. At least that is my limited understanding of it. |
|
|
|
2006-01-05
#38 |
||
|
I hate beeing doom and gloom, so... ...CM- I was just going through your files today, and I wanted to let you and the ultrashock world know that this is the clearest pure flash example of how design patterns can be implemented that I have seen. Really good example. Thanks for that. |
|
|
2006-01-05
#39 |
||
|
Originally posted by tcoulson Well, you're making me blush now (and sentimental) I hate beeing doom and gloom, so... ...CM- I was just going through your files today, and I wanted to let you and the ultrashock world know that this is the clearest pure flash example of how design patterns can be implemented that I have seen. Really good example. Thanks for that. ![]() I think agree with you now about the setters/getters thing. Sometimes I forget the spirit in which flash was intended and get all strict and stuff. It really is a kick ass dynamic/visual/code hybrid monster ![]() See what you are doing to me? Smiley’s all over the place
|
|
|
|
2006-01-05
#40 |
||
|
Last edited by RAMPAGE201 : 2006-01-06 at 07:37.
Very Cool Codemonkey. I love the graphics. (I did a little tweek edit to fix the image next to url thing so you can read it without scrolling horizontally.. aparently it needed a crlf in there).
|
|
| 123>>> | Page 1 of 6 |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|


. Anyway, if you would like to know what this gallery is all about read on, otherwise just download the source and see if you can use it. It’s not really a tutorial and it may or may not be very dry to plow through. I don't tell very well, but let’s just get down to it shall we?
218 comments
| 14610 views



17 Creative Assets

Linear Mode
Fine, I’ll treat you on a diagram for your sore eyes then.
I took over Moock’s style for these diagrams, since I already had so much use from his book Essential Actionscript 2. You can see at the colors what pattern they belong to and how the gallery classes consists of these.
The two interfaces Observer and View define a set of functions for their patterns and AbstractView implements all of these to define the basic functionality for a view of the mvc pattern. This is to observe an observable object, the model, and to be able to communicate back to the model either directly to retrieve data or more commonly via the controller to request changes. GalleryView is such a view as is ControlsView.
GalleryView creates the interface of the gallery and ControlsView is part of that (with the previous and next buttons). First I had GalleryView as the only view, but then it was hard to communicate with the model, which only the GalleryView could do. So I made the controls also a view.
Then there is the Controller, who can directly talk to the model and optionally make changes. The GalleryController receives requests from both views and makes sure the model reacts accordingly. The buttons ask the model to activate the previous or next image, the thumbnails ask for a specific image and the GalleryView requests that the model loads the next image from xml after the thumbnails bar on the left has preloaded and shown the last thumbnail.
And then there is the observable, our model, which contains all the gallery data (title, image list, current activated image and percentage of total images loaded from xml).
Last is the GalleryUpdate class. This class contains all the data I just mentioned and the nature of the update. Or rather the state the model is in (starting up, loading images, viewing images etc.).
Here’s an image that shows the various classes.
These are all the custom classes in the gallery project. All the white classes are actually assets in the library with a class attached to them. These have the benefit to already have graphical stuff done and can easily be changed to alter the way the gallery looks. They actually have more objects, but they are all MovieClips which I haven’t listed here, but they are part of the white classes.
The GalleryView has a ViewArea, the main window where the image is viewed. Also has the NavBar, which contains the ThumbImages. GalleryView also has the ControlsView, which has the button previous and next. The NavBar also has the slider.
ViewArea and ThumbImage extend PreloadImage because they both have load an image from an url and both need to preload them before showing. Perhaps a poor choice of name, but it does the job. PreloadImage makes use of our custom preloader class, which is actually just a listener for a MovieClipLoader, as the cliploader calls methods on its listeners like onGetProgress().
So that’s it. I’m not going into the classes, that would be too much work, but I have commented them enough so you should be able to understand it. Look back at these diagrams to see how the classes relate.