-
Senior Member
How to convert AS2 - 3
I have this dynamic news updater that I need to be AS3. Any ideas?
Code:
function loadMyText(evt)
{
var _loc2 = new LoadVars();
_loc2.load("content.html");
_loc2.onLoad = function (success)
{
if (success)
{
my_txt.text = this.content;
my_title.text = this.title;
}
else
{
trace ("Could not load text file.");
} // end else if
};
} // End of the function
this.createClassObject(mx.controls.UIScrollBar, "my_sb", 20);
my_sb.setScrollTarget(my_txt);
my_sb.setSize(16, my_txt._height);
my_sb.move(my_txt._x + my_txt._width + 5, my_txt._y);
loadMyText();
var flash_css = new TextField.StyleSheet();
flash_css.load("styles.css");
my_txt.styleSheet = flash_css;
-
If you post your file(s), we can convert it for you properly.
-
Senior Member
This is what I have come up with so far but I still get a few errors on lines 7 and 14. What do you think?
Code:
package {
function loadMyText(evt)
import flash.text.TextField;
{
public var _loc2 = new LoadVars();
_loc2.load("content.html");
_loc2.onLoad = public function (success)
{
if (success)
{
my_txt.text = this.content;
my_title.text = this.title;
}
else
{
trace ("Could not load text file.");
} // end else if
};
} // End of the function
this.createClassObject(mx.controls.UIScrollBar, "my_sb", 20);
my_sb.setScrollTarget(my_txt);
my_sb.setSize(16, my_txt.height);
my_sb.move(my_txt.x + my_txt.width + 5, my_txt.y);
loadMyText();
var flash_css = new TextField.StyleSheet();
flash_css.load("styles.css");
my_txt.styleSheet = flash_css;
}
-
This will load the text, you can add the rest:
PHP Code:
package { import fl.controls.UIScrollBar; import flash.display.Sprite; import flash.events.Event; import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.net.URLRequest; import flash.text.TextField; public class DocumentClass extends Sprite { private var my_sb:UIScrollBar; private var my_loader:URLLoader; public function DocumentClass():void { my_loader = new URLLoader(); my_sb = new UIScrollBar(); my_loader.addEventListener(Event.COMPLETE, onHTMLloaded); my_loader.dataFormat = URLLoaderDataFormat.VARIABLES; my_loader.load(new URLRequest("index.html")); } private function onHTMLloaded(e:Event):void { my_txt.text = e.target.data.content; my_title.text = e.target.data.title; my_sb.scrollTarget = my_txt; my_sb.setSize(16, my_txt.height); my_sb.move(my_txt.x + my_txt.width + 5, my_txt.y); my_sb.update(); } } }
Put this in a file with your swf called "DocumentClass.as" and enter the document class on your properties dialog as "DocumentClass".
-
Senior Member
I got this output error when I ran it.
PHP Code:
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables$iinit()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
-
whats the code inside your index.html file?
-
Senior Member
PHP Code:
&title=Latest News
&content=
<img src="photo_gallery1.jpg" width="61" height="64" align="left"><a href="http://www.entheosweb.com/Flash/free_flash_photo_gallery.asp" class="heading">Free Flash and XML Photo Galleries</a></p>
<p>Download any of the Entheos free Dynamic Flash Photo Galleries today! You don't need the Flash software for editing the gallery. You can easily add, edit or delete pictures by editing the xml file in Notepad. All images are loaded externally. Add unlimited number of images!</p>
<img src="games.jpg" width="58" height="51" align="left"><a href="http://www.entheosweb.com/flash_games/index.asp" class="heading">Free Flash Games</a>
Free educational Flash games for kids including coloring, drawing, puzzles, memory game, join the dots, shooting and more.<br/>
<img src="background.jpg" width="58" height="51" align="left"><a href="http://www.entheosweb.com/fireworks/background1.asp" class="heading">Free Website Backgrounds</a>
Download these attractive free website background images for your website.
-
Should be:
PHP Code:
title=Latest News &content= <img src="photo_gallery1.jpg" width="61" height="64" align="left"><a href="http://www.entheosweb.com/Flash/free_flash_photo_gallery.asp" class="heading">Free Flash and XML Photo Galleries</a></p> <p>Download any of the Entheos free Dynamic Flash Photo Galleries today! You don't need the Flash software for editing the gallery. You can easily add, edit or delete pictures by editing the xml file in Notepad. All images are loaded externally. Add unlimited number of images!</p> <img src="games.jpg" width="58" height="51" align="left"><a href="http://www.entheosweb.com/flash_games/index.asp" class="heading">Free Flash Games</a> Free educational Flash games for kids including coloring, drawing, puzzles, memory game, join the dots, shooting and more.<br/> <img src="background.jpg" width="58" height="51" align="left"><a href="http://www.entheosweb.com/fireworks/background1.asp" class="heading">Free Website Backgrounds</a> Download these attractive free website background images for your website.
-
Senior Member
I am not sure what I am doing wrong man, here is a zip file that contains all of my old and new work. The ~news was the old one. NEWS FILES
-
Sorry, missed the most important part:
my_txt.htmlText = e.target.data.content;
my_title.htmlText = e.target.data.title;
-
Senior Member
Thank you so much it works great. Whe I add it into my main document I get a bunch of 1046 errors for every button I have on the timeline. I'm going to look it up but I may be back with another question for you.
Thanks again!
-
Senior Member
Ok it is because this function, does it make sense to you?
PHP Code:
function buttonNavClick1(event:MouseEvent):void{
gotoAndStop("registry");
};
-
Senior Member
So I was thinking about it and I moved all of my AS from my main file into the DocumentClass.as file. There are no more errors but my btns do not work. Here is the code do you know why they will not work?
PHP Code:
// News Application
package {
import fl.controls.UIScrollBar;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.text.TextField;
public class DocumentClass extends Sprite
{
private var my_sb:UIScrollBar;
private var my_loader:URLLoader;
public function DocumentClass():void
{
my_loader = new URLLoader();
my_sb = new UIScrollBar();
my_loader.addEventListener(Event.COMPLETE, onHTMLloaded);
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(new URLRequest("content.html"));
}
private function onHTMLloaded(e:Event):void
{
my_txt.htmlText = e.target.data.content;
my_title.htmlText = e.target.data.title;
my_sb.scrollTarget = my_txt;
my_sb.setSize(16, my_txt.height);
my_sb.move(my_txt.x + my_txt.width + 5, my_txt.y);
my_sb.update();
}
}
}
// Main Navigation
btn_registry.addEventListener(MouseEvent.CLICK, buttonNavClick1);
function buttonNavClick1(event:MouseEvent):void{
gotoAndStop("registry");
};
btn_inursery.addEventListener(MouseEvent.CLICK, buttonNavClick2);
function buttonNavClick2(event:MouseEvent):void{
gotoAndStop("inursery");
};
btn_sales.addEventListener(MouseEvent.CLICK, buttonNavClick3);
function buttonNavClick3(event:MouseEvent):void{
gotoAndStop("sales");
};
btn_news.addEventListener(MouseEvent.CLICK, buttonNavClick4);
function buttonNavClick4(event:MouseEvent):void{
gotoAndStop("news");
};
// Timer Movie Clips
if (currentLabel == "registry") {
mc_1.gotoAndPlay (1);
}
if (currentLabel == "inursery") {
mc_2.gotoAndPlay (41);
}
if (currentLabel == "sales") {
mc_3.gotoAndPlay (83);
}
if (currentLabel == "news") {
mc_4.gotoAndPlay (124);
}
//Timer Buttons
btn_1.addEventListener(MouseEvent.CLICK, clearBtn1);
function clearBtn1(event:MouseEvent):void{
gotoAndStop("registry");
};
btn_2.addEventListener(MouseEvent.CLICK, clearBtn2);
function clearBtn2(event:MouseEvent):void{
gotoAndStop("inursery");
};
btn_3.addEventListener(MouseEvent.CLICK, clearBtn3);
function clearBtn3(event:MouseEvent):void{
gotoAndStop("sales");
};
btn_4.addEventListener(MouseEvent.CLICK, clearBtn4);
function clearBtn4(event:MouseEvent):void{
gotoAndStop("news");
};
-
Your listeners and functions need to be inside the class, you have them all outside the class currently.
PHP Code:
public function DocumentClass():void { my_loader = new URLLoader(); my_sb = new UIScrollBar(); my_loader.addEventListener(Event.COMPLETE, onHTMLloaded); my_loader.dataFormat = URLLoaderDataFormat.VARIABLES; my_loader.load(new URLRequest("content.html")); btn_registry.addEventListener(MouseEvent.CLICK, buttonNavClick1); }
private function buttonNavClick1(event:MouseEvent):void{ gotoAndStop("registry"); };
-
Senior Member
When I put them inside the class the script is fine. But when I test it I compile errors on every
PHP Code:
private function buttonNavClick1(event:MouseEvent):void{
line. It is a 1046: Type was not found or was not compile-time constant: MouseEvent.
-
Add:
PHP Code:
import flash.events.Event; import flash.events.MouseEvent;// Add this
-
Senior Member
I am not sure why I can not get this to work. Can you take a look at my files and tell me what I am doing wrong? Thank you TEST FILES
-
Here you go, let me know if you have questions as I didn't have time to comment this :d
http://www.stevestalder.com/test.zip
-
Senior Member
When you get a chance check out the fla. when you test it the animation dosen't play and the main nav btns dont work all the time.
-
Re-download from my link above. I made some more changes for you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|