Im currently working on a website and have a flash gallery up and running but would开发者_如何学C like to be able to link clients to a specific photo in a specific gallery. How would I go about coding this, because i know that it is possible but i cant figure out how. I am using Flash CS3 and AS3.
You can use the SWFAddress library.
No need to do anything complex here... Just add parameter to your URL identificating image. You can pass that parameter to FlashVars via Javascript, or you can link to swf directly and read its url via Application.application.url. After you read parameter, you can show corresponding image in swf (or default view if parameter is missing).
You could create a class that you would use for each image, this class would have a url property , but you could also have a gallery & client property depending on what you're trying to achieve.
When reading data from an XML , I tend to create my objects directly from the XML data.
for instance I would get my image object from an xml node like this
images image ID 1 /ID url http://example.com/images/img1.jpg /url client John Smith /client clientURL http://clientSite.com/ /clientURL galleryID 6 /galleryID /image etc... /images
var imageData:XMLList = xml..images; //then I use a "for" loop to iterate thru imageData , inside the "for" loop I would have var image:Image = new Image(); //the return values are XMLList so they need to be coerced image.imageURL = String(imageData[i].url); image.clientURL = String(imageData[i].clientURL); etc...
You can then store your Image objects in an array and manipulate them as you need. Since the Image class extends Sprite, you can consider adding the loaded bitmap to the corresponding object.
//if you're using a for loop var image:Image = imagesArray[i] as Image; loader.name = i.toString(); loader.load( new URLRequest(image.imageURL ) ); function completeHandler(event:MouseEvent):void { var index:int = int(event.currentTarget.loader.name); var image:Image = imagesArray[index] as Image; image.addChild(event.currentTarget.loader.content ); }
In the Image class , add a MouseEvent listener to call navigateToURL and if a user clicks on the image she will be redirected to the image specific url
private function mouseClickHandler(event:MouseEvent):void { navigateToURL( new URLRequest(_clientURL ) ); }
Here's a basic example:
package { import flash.display.Sprite; public class Image extends Sprite { private var _client:String; private var _galleryID:int; private var _galleryName:String; private var _imageID:int; private var _imageURL:String; public function Image() { } public function get imageURL():String { return _imageURL; } public function set imageURL(value:String):void { _imageURL = value; } public function get imageID():int { return _imageID; } public function set imageID(value:int):void { _imageID = value; } public function get galleryName():String { return _galleryName; } public function set galleryName(value:String):void { _galleryName = value; } public function get galleryID():int { return _galleryID; } public function set galleryID(value:int):void { _galleryID = value; } public function get client():String { return _client; } public function set client(value:String):void { _client = value; } } }
精彩评论